Tuesday, April 17, 2018

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

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');



from Laravel Questions and Answers https://laravelquestions.com/laravel/cache-remember-specific-parameter-in-get-request-end-up-the-same-result-laravel-5/
via Lzo Media

No comments:

Post a Comment