英文:
How to make correct pagination with GET parameters?
问题
我正在使用Laravel进行数据分页输出。一切都运行良好。我有自己的分页模板。它写成这样:
{{ $houses->links('catalogs.paginate') }}
然而,当我在页面上使用一些参数仍然搜索数据时,GET参数不会进入分页。
我尝试这样写:
{{ $houses->links('catalogs.paginate')->withQueryString() }}
或者
控制器
...
public function Category($cat, Request $request) {
$houses = House::with('areas')->where('format_house', '=', $format_house)->paginate(4)->appends(request()->query());
return view('category_catalog', compact('title', 'houses'));
}
模板
{{ $houses->links('catalogs.paginate') }}
没有什么帮助。应该如何正确操作?
英文:
I am doing data output with pagination on laravel. Everything works great. I have my own pagination template. It's written like this:
{{ $houses->links('catalogs.paginate') }}
However, when I still search for data on the page by some parameters, the GET parameters do not get into pagination.
I tried to write like this:
{{ $houses->links('catalogs.paginate')->withQueryString() }}
Or
controller
...
public function Category($cat, Request $request) {
$houses = House::with('areas')->where('format_house', '=', $format_house)->paginate(4)->appends(request()->query());
return view('category_catalog', compact('title', 'houses'));
}
Maket
{{ $houses->links('catalogs.paginate') }}
Nothing helps. How to do it right?
答案1
得分: 1
你已经很接近,你调用方法的排列顺序不正确,你必须最后调用 links
方法。
$houses->paginate(15)->withQueryString()->links('catalogs.paginate')
或者
$houses->paginate(15)->appends(request()->query())->links('catalogs.paginate')
英文:
You're already close, the arrangement of the methods you're calling is incorrect, you must call the links
method last.
$houses->paginate(15)->withQueryString()->links('catalogs.paginate')
OR
$houses->paginate(15)->appends(request()->query())->links('catalogs.paginate')
答案2
得分: 1
请看以下翻译:
Try this
{{ $houses->appends($_GET)->links('catalogs.paginate') }}
OR
{{ $houses->appends(request()->query())->links('catalogs.paginate') }}
英文:
Try this
{{ $houses->appends($_GET)->links('catalogs.paginate') }}
OR
{{ $houses->appends(request()->query())->links('catalogs.paginate') }}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论