jlrdw's avatar
Level 75

Paginator another episode

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
0 likes
2 replies
jlrdw's avatar
Level 75

Even though the docs explain usage of a custom template, I'll show simple usage here:

As example, say I have made a folder under views called cpag, and named the custom template custom:

views/cpag/custom.blade.php

Then in the view where used,

<?php echo $dogs->links('cpag.custom'); ?>

of course if you have appends then:

<?php echo $dogs->appends($append_array)->links('cpag.custom'); ?>

Just convert to blade if desired.

5 likes

Please or to participate in this conversation.