src/Traits/Favoriteable.php
/**
     * Add this Object to the user favorites
     * 
     * @param  int $user_id  [if  null its added to the auth user]
     */
Add this Object to the user favorites

@param  int $user_id  [if  null its added to the auth user]
Add this Object to the user favorites @param int $user_id [ if null its added to the auth user ]
public function addFavorite($user_id = null)
    {
        $data = [
            'user_id' => $user_id ?: Auth::id(),
            'session_id' => Session::getId(),
        ];
        $favorite = $this->favorites()
            ->where('user_id', $data['user_id'])
            ->where('session_id', $data['session_id'])
            ->first();
        if ($favorite) return true;
        $favorite = new Favorite($data);
        $this->favorites()->save($favorite);
        return true;
    }
public function addFavorite ( $ user_id = null ) { $ data = [ 'user_id' => $ user_id ? : Auth :: id ( ) , 'session_id' => Session :: getId ( ) , ] ; $ favorite = $ this -> favorites ( ) -> where ( 'user_id' , $ data [ 'user_id' ] ) -> where ( 'session_id' , $ data [ 'session_id' ] ) -> first ( ) ; if ( $ favorite ) return true ; $ favorite = new Favorite ( $ data ) ; $ this -> favorites ( ) -> save ( $ favorite ) ; return true ; }
Add this Object to the user favorites
Add this Object to the user favorites