Laravel Pagination links not including other GET parameters

Nyxynyx picture Nyxynyx · Jun 18, 2013 · Viewed 95.8k times · Source

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/users?gender=female&body=hot, the pagination links produced only contain the page parameter and nothing else.

Blade Template

{{ $users->link() }}

There's a ->append() function for this, but when we don't know how many of the GET parameters are there, how can we use append() to include the other GET parameters in the paginated links without a whole chunk of if code messing up our blade template?

Answer

Alexandre Danault picture Alexandre Danault · Jun 18, 2013

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'))
]);