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?
2
Answers
You’re already close, the arrangement of the methods you’re calling is incorrect, you must call the
links
method last.OR
Try this
{{ $houses->appends($_GET)->links(‘catalogs.paginate’) }}
OR
{{ $houses->appends(request()->query())->links(‘catalogs.paginate’) }}