How to automatically append query string to laravel pagination links?

user2067888 picture user2067888 · Jul 22, 2014 · Viewed 46.4k times · Source

I am working on search filter on checkbox click, with Laravel and Ajax call. So I get results when I click on a checkbox. my query is as follows:

    $editors = User::with(['editor.credentials','editor.specialties','editor.ratings']);
        $temp=$editors->whereHas('editor', function($q) use ($a_data){
            $q->whereHas('specialties',function($sq) use($a_data){
            $sq->whereIn('specialty',$a_data);
            });
        })->paginate(2);

This gives me all the data I need. however how should I get the links for pagination?

    $temp->setBaseUrl('editors');
    $links = $temp->links()->render();

I am currently doing this and with $links which I am sending over as response to ajax call, I set the pagination with $links data. Now, I need to append the query to next page like page=2?query="something". I don't know how should I go about appending the remaining query result links to next page links. i.e. I don;t know what should come in the query="something" part. Can someone guide me. thanks

Answer

Daud khan picture Daud khan · Feb 1, 2017
{{ $users->appends($_GET)->links() }}

It will append all query string parameters into pagination link