jlrdw
1 year ago
2674
2
Guides

Paginator another episode

Posted 1 year ago by jlrdw

I recently had a client who did not want the regular pagination links, so I set up Simple Pagination.

But then they still wanted to see current page and number of pages. Simple Pagination was out due to no last page, from docs

$results->lastPage() (Not available when using simplePaginate)

Since I knew how to write custom pagination templates, I wrote this, actually some copy and paste from the regular paginator template, and inserted in the middle the page and total.

Looks like this: In case you can't see image: https://i.imgur.com/qQsiLNN.jpg

Here is the template, can style as you wish. Hope it helps someone.

@if ($paginator->hasPages())
    <ul class="pagination">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="disabled"><span>{{ __('Prev') }}</span></li>
        @else
            <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">{{ __('Prev') }}</a></li>
        @endif
        
        
        
        {{ "Page " . $paginator->currentPage() . "  of  " . $paginator->lastPage() }}
       
        
        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">{{ __('Next') }}</a></li>
        @else
            <li class="disabled"><span>{{ __('Next') }}</span></li>
        @endif
    </ul>
@endif

Please sign in or create an account to participate in this conversation.