I am using Eloquent together with Laravel 4\'s Pagination class.
Problem: When there are some GET parameters in the URL, eg: http://site.com/u
Laravel 7.x has added new method to paginator:
->withQueryString()
So you can use it like:
{{ $users->withQueryString()->links() }}
For laravel below 7.x use:
{{ $users->appends(request()->query())->links() }}
You could use
->appends(request()->query())
Example in the Controller:
$users = User::search()->order()->with('type:id,name')
->paginate(30)
->appends(request()->query());
return view('users.index', compact('users'));
Example in the View:
{{ $users->appends(request()->query())->links() }}
LARAVEL 5
The view must contain something like:
{!! $myItems->appends(Input::except('page'))->render() !!}
for who one in laravel 5 or greater in blade:
{{ $table->appends(['id' => $something ])->links() }}
you can get the passed item with
$passed_item=$request->id;
test it with
dd($passed_item);
you must get $something value
Be aware of the Input::all()
, it will Include the previous ?page=
values again and again in each page you open !
for example if you are in ?page=1
and you open the next page, it will open ?page=1&page=2
So the last value page takes will be the page you see ! not the page you want to see
Solution : use Input::except(array('page'))
In Laravel 7.x you can use it like this:
{{ $results->withQueryString()->links() }}