Laravel 分页链接不包括其他 GET 参数 [英] Laravel Pagination links not including other GET parameters
问题描述
我将 Eloquent 与 Laravel 4 的 Pagination 类一起使用.
I am using Eloquent together with Laravel 4's Pagination class.
问题:当 URL 中有一些 GET 参数时,例如:http://site.com/users?gender=female&body=hot
,生成的分页链接仅包含 page
参数,不包含其他任何内容.
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.
刀片模板
{{ $users->link() }}
有一个->append()
函数,但是当我们不知道有多少GET参数时,我们如何使用append()
code> 在分页链接中包含其他 GET 参数,而没有一大块 if
代码弄乱了我们的刀片模板?
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?
推荐答案
Connor 对 Mehdi 的回答的评论是完成这项工作所必需的.感谢他们的澄清.
Connor's comment with Mehdi's answer are required to make this work. Thanks to both for their clarifications.
->appends()
可以接受一个数组作为参数,你可以传递 Input::except('page')
,这应该可以解决问题.
->appends()
can accept an array as a parameter, you could pass Input::except('page')
, that should do the trick.
示例:
return view('manage/users', [
'users' => $users->appends(Input::except('page'))
]);
这篇关于Laravel 分页链接不包括其他 GET 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!