Ben Beri
Ben Beri

Reputation: 1201

PHP Laravel - keep using the passed paramaters in the url for other urls like pagination links

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?

Upvotes: 0

Views: 264

Answers (1)

Usman Jdn
Usman Jdn

Reputation: 827

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

Upvotes: 1

Related Questions