[英]Laravel - Route that may contain a pagination/query url at the end - Pagination url doesn't add to the query url, it replaces it
So I have a products page where you may browse all products or browse queried products if you choose to. 因此,我有一个产品页面,您可以在其中浏览所有产品,也可以浏览查询的产品。 However in both cases they must have pagination. 但是,在两种情况下,它们都必须具有分页功能。 Here is my route: 这是我的路线:
Route::get('/products/{gender}/{subcategory_name}', [
'uses' => 'ProductsController@showProducts',
'as' => 'products'
]);
For the pagination links I use $model->links()
in my views. 对于分页链接,我在视图中使用$model->links()
。 Both the pagination and query work. 分页和查询均有效。 When you decide to query the items you must still paginate them. 当您决定查询项目时,仍必须对它们进行分页。 However when I click to go to the second page the pagination url deletes my query url. 但是,当我单击以转到第二页时,分页网址会删除我的查询网址。 The result is loosing the queried products and getting to the second page but with ALL products, not the Queried ones. 其结果是失去所查询的产品和获得的第二页,但所有产品,而不是被查询的。 Here is an step by step walkthrough for clarification: 以下是逐步进行说明的步骤:
Solutions and advice are welcome. 欢迎提供解决方案和建议。 Thanks in advance! 提前致谢!
You need to tell Laravel to append your own query parameters to the links()
method, for example: 您需要告诉Laravel将您自己的查询参数附加到links()
方法,例如:
{{ $model->appends(['color' => Request::input('color')])->links() }}
To have the query params dynamically you could use something like: 要使查询参数动态化,您可以使用类似以下内容的方法:
{{ $model->appends(Request::except('page'))->links() }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.