How to automatically append query string to laravel pagination links?
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);
As of Laravel 7, you can call the withQueryString()
method on your Paginator
instance.
Quote from the documentation:
If you wish to append all current query string values to the pagination links you may use the withQueryString method:
{{ $users->withQueryString()->links() }}
See "Appending To Pagination Links": https://laravel.com/docs/7.x/pagination#displaying-pagination-results
{{ $users->appends($_GET)->links() }}
It will append all query string parameters into pagination link
Append all input except the actual page, form token and what you don't want to pass:
$paginatedCollection->appends($request->except(['page','_token']));