app/Models/Traits/Likeable.php
/**
     * Fetch records that are liked by a given user.
     * Ex: Book::whereLikedBy(123)->get();
     */
Fetch records that are liked by a given user.
Fetch records that are liked by a given user .
public function scopeWhereLikedBy($query, $userId = null)
    {
        if (is_null($userId)) {
            $userId = auth()->id();
        }
        return $query->whereHas('likes', function ($q) use ($userId) {
            $q->where('user_id', '=', $userId);
        });
    }
public function scopeWhereLikedBy ( $ query , $ userId = null ) { if ( is_null ( $ userId ) ) { $ userId = auth ( ) -> id ( ) ; } return $ query -> whereHas ( 'likes' , function ( $ q ) use ( $ userId ) { $ q -> where ( 'user_id' , '=' , $ userId ) ; } ) ; }
Fetch records that are liked by a given user.
Fetch records that are liked by a given user .