T
T
truevolkolak2022-02-28 14:00:06
Laravel
truevolkolak, 2022-02-28 14:00:06

Laravel pagination. Breaks sorting through get parameters. How to win?

Laravel 5.8.
Made filtering products through get-requests of the form:
?1=дуб,ясень&15=3&7=лак,масло

When you go to any other page (pagination), the get-request breaks and turns into:
?0=дуб,ясень&1=3&2=лак,масло&page=2
That is, the first parameter is equal to zero, and each next one is simply increased by one.
I render pagination like this:

{{ $products->appends(request()->input())->links('layouts.pagination') }}


What could be causing this and how to overcome it? Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
inFureal, 2022-02-28
@inFureal

Here

$products->links('layouts.pagination')->withQueryString()

The entire request will be glued to the pagination.
And what else for 1, 15, 3, 7? It is better to write normal parameter names

A
Anton Anton, 2022-02-28
@Fragster

in controller

...
$products = $xxx->paginate(15)->appends(request()->query());
...

and in the layout
{{ $products->links('layouts.pagination') }}

V
vism, 2022-02-28
@vism

{!! (method_exists($products, 'links') ? $products->appends(request()->except(['page']))->render() : "") !!}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question