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
I think you should use this code in Laravel 5.
Also this will work not only with parameter page
but also with any other parameter(s):
$users->appends(request()->input())->links();
Personally, I try to avoid using Facades as much as I can. Using global helper functions is less code and much elegant.
UPDATE:
Do not use Input
Facade as it is deprecated in Laravel v6+
Use this construction, to keep all input params but page
{!! $myItems->appends(Request::capture()->except('page'))->render() !!}
Why?
1) you strip down everything that added to request like that
$request->request->add(['variable' => 123]);
2) you don't need $request as input parameter for the function
3) you are excluding "page"
PS) and it works for Laravel 5.1
EDIT: Connor's comment with Mehdi's answer are required to make this work. Thanks to both for their clarifications.
->appends()
can accept an array as a parameter, you could pass Input::except('page')
, that should do the trick.
Example:
return view('manage/users', [
'users' => $users->appends(Input::except('page'))
]);
Not append()
but appends()
So, right answer is:
{!! $records->appends(Input::except('page'))->links() !!}
Pass the page number for pagination as well. Some thing like this
$currentPg = Input::get('page') ? Input::get('page') : '1';
$boards = Cache::remember('boards'.$currentPg, 60, function(){ return WhatEverModel::paginate(15); });
Include This In Your View Page
$users->appends(Input::except('page'))