Laravel 分页获取变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22160710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel pagination get variables
提问by notforever
I have a page that list apartments depending on book dates like this
我有一个页面,根据这样的预订日期列出公寓
mypage.com/finder?date-from=2011-03-04&date-to=2011-03-12
Everything is right, I am getting the date-from and date-get from the url and searching the database with those values. The problem is when I paginate and I click to go to another page the url changes to.
一切正常,我从 url 获取 date-from 和 date-get,并使用这些值搜索数据库。问题是当我分页并单击以转到 url 更改为的另一个页面时。
mypage.com/finder?page=9
and get an error Value must be provided
并得到一个错误值必须提供
The correct url must be
正确的网址必须是
mypage.com/finder?date-from=2011-03-04&date-to=2011-03-12&page=9
I am using paginate at the controller and $searchResult->links(); to generate the links
我在控制器上使用 paginate 和 $searchResult->links(); 生成链接
What can I do pass the date values from page to page so the pagination works?
我该怎么做才能将日期值从页面传递到页面,以便分页工作?
Thanks
谢谢
回答by Joseph Silber
If you want to tack on existing query string data, use this:
如果要添加现有查询字符串数据,请使用以下命令:
$searchResult->appends(array(
'date-from' => Input::get('date-from'),
'date-to' => Input::get('date-to'),
));
Read the docs: Appending To Pagination Links.
阅读文档:附加到分页链接。
You can shorten that a little:
你可以缩短一点:
$searchResult->appends( Input::only('data-from', 'date-to') );
which ends up being the same thing.
最终是同样的事情。
回答by Darren Craig
you can do this using the 'appends' feature. There are examples in the documentation: http://laravel.com/docs/pagination
您可以使用“附加”功能执行此操作。文档中有示例:http: //laravel.com/docs/pagination