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:
$editor
For the latest version of Laravel at the moment (5.2), you can just use the Request facade to retrieve the query string and pass that to your paginator's appends() method
$input = Request::input();
$myModelsPaginator = App\Models\MyModel::paginate();
$myModelsPaginator->appends($input);
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);
you can used request helper in view as same
{{ $users->appends(request()->query())->links() }}
Append all input except the actual page, form token and what you don't want to pass:
$paginatedCollection->appends(request()->except(['page','_token']));
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