bufferoverflow's avatar

Laravel pagination links reset the GET query

I have a form in a Real Estate website that searches for properties with filters (parameters) like rooms, baths, province... I print the results using pagination ->paginate(6).

The search goes well and the results show up well filtered, but when I click on another page all the parameters get replaced for ?page=2.

When I do a search: /properties/search?type=terrain&service=sell&province=&city=&baths=&rooms=&sort=all

Then I click on the next page: /properties/search?page=2

0 likes
2 replies
arthvrian's avatar
Level 2

Appending To Pagination Links

You may append to the query string of pagination links using the appends method. For example, to append sort=votes to each pagination link, you should make the following call to appends:

{{ $users->appends(['sort' => 'votes'])->links() }}

in your case you can use $request->query() as parameter for appends

1 like
s4muel's avatar
    ...
    ->paginate(6)
    ->appends(request()->query());
1 like

Please or to participate in this conversation.