0

I set filters for my customers list:

?countries=Germany,France&status=1,3

And I have Previous and Next pagination.

The following example is in Blade template

@if ($paginator->hasPages())
    <ul class="pagination center" role="navigation">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="disabled" aria-disabled="true"><span>@lang('pagination.previous')</span></li>
        @else
            <li><a href="{{ $paginator->previousPageUrl() }}" class="page-link" rel="prev">@lang('pagination.previous')</a></li>
        @endif

        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li><a href="{{ $paginator->nextPageUrl() }}"  class="page-link" rel="next">@lang('pagination.next')</a></li>
        @else
            <li class="disabled" aria-disabled="true"><span>@lang('pagination.next')</span></li>
        @endif
    </ul>
@endif

However, these links do not contain the parameters that were in the url.

What is the best way to save these filters, without saving it to session or cookies because that's not how it should be? or should it?

Ben Beri
  • 1,101
  • 4
  • 23
  • 64
  • possible duplicate of https://stackoverflow.com/questions/17159273/laravel-pagination-links-not-including-other-get-parameters ? – Tschitsch Aug 14 '18 at 11:34

1 Answers1

1

try this => $paginator->appends(request()->query->all())->previousPageUrl();

Usman Jdn
  • 807
  • 8
  • 21
  • What if I just want to make an url, e.g url("/people/")? I tried url("/people/search/customer", array_merge(request()->all()))}} and it makes my parameters like /germany/ etc and not via params ?countries – Ben Beri Aug 14 '18 at 11:53
  • 1
    replace array_merge with `array_replace(Request::all(), ['countries'=>'germany']) )` – Usman Jdn Aug 14 '18 at 12:02