Cache remember specific parameter in get request end up the same result - Laravel 5

trying too search any matching name get request with different parameter for example: search?q=anhar showing the result with the name anhar then when I change anhar with aslam its not querying again and endup with the same result

here's my controller

public function search(Request $request)
    {
        $q = $request->get('q');
        $q = Cache::remember('q', 30*60, function() use ($q) {
            $user = User::select('users.id', 'users.first_name', 'users.last_name', 'profiles.location', 'profiles.occupation')
                        ->leftJoin('profiles', 'users.id', '=', 'profiles.member_id')
                        ->where('first_name', 'LIKE', '%'.$q.'%')
                        ->orWhere('last_name', 'LIKE', '%'.$q.'%')
                        ->paginate(10);
            return $user;
        });
        return view('search.result', compact('q'));
    }

and this route

Route::get('/search', 'PublicController@search')->name('search.result');

1 answer

  • answered 2018-04-17 06:03 Aslam

    I have found the answer with replacing Cache::remember('q') with Cache::remeber($q)