Search code examples
laravel-4pagination

How to automatically append query string to laravel pagination links?


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


Solution

  • Check the answer from @Arda, as it's global solution. Below you can find how to do it manually.

    Use appends on Paginator:

    $querystringArray = Input::only(['search','filter','order']); // sensible examples
    
    // or:
    $querystringArray = ['queryVar' => 'something', 'anotherVar' => 'something_else'];
    
    $temp->appends($querystringArray);