php - Filtering search results in laravel

one text

Solution:

So instead of checking for only keyword, you will have to add another clause that checks for subscription of the current user.

$videos = Video::whereHas('packages.subscription', function($query) {
        $query->where('subscription.user_id', auth()->id());
    })
    ->where(function($query) use ($keyword) {
        $query->where('video_title', 'LIKE', "%$keyword%")
            ->orWhere('video_file', 'LIKE', "%$keyword%");
    })
    ->latest()
    ->paginate($perPage);

whereHas will check whether video has a subscription and subscription's user_id is the same as current user id (auth()->id()).

Source