taishi's avatar

Laravel Pagination has

Hello guys,

I am having a problem with the generated pagination. The pagination links are having ellipsis(...) and after those ellipsis, the page numbers seem to be showing the last 2 link pages of the pagination.

So the generated page links looks like this;

< | 1 | 2 | 3 | ... | 20 | 22 | >

Here is my code for the database paginating.

public function scopeBlogs($query, $limit = NULL){
        $query->where('blog', 1)->whereNull('deletedby')->orderBy('createddate', 'desc');
        if(!is_null($limit)){
            return $query->paginate($limit);
        }
        return $query->get();
    }

And on the front-end as usual I am calling the {{ $blogs->links() }}.

Here is the screenshot of the generated pagination on my project - https://www.dropbox.com/s/4vlxwf0as3kps2o/2018-03-05_0710.png?dl=0

0 likes
13 replies
bobbybouwmann's avatar

What is your question? Do you want them gone? Do you want another solution for this?

taishi's avatar

Hi bobby, I want them gone and display them the way it should be. At the moment my table contains like 75 records and I am showing 3 records per page.

Hope it helps, thanks!

taishi's avatar

Hi Snapey, what I mean is that it shouldn't have the ellipsis as it isn't suppose to be there.

Normally, it will have like 1 - 10 links of pages which will not have any other links(special character texts) within that are disabled, so I'm wondering why are there ellipsis showing out of the generated page links.

Snapey's avatar

This is the standard behaviour. It shows some of the links towards the front and some towards the end. Otherwise the list of numbers would possibly be very long, and no user wants to randomly click on page 12 or 16. The ellipsis shows that there are pages missing.

Or is it me missing the point?

Have a look at the index of discussions on this site

« 1 2 3 4 5 6 7 8 ... 4014 4015 »

Would you suggest it should list every page from 1 to 4015?

taishi's avatar

I don't think this a standard behavior as I have used pagination features as well in the past from different frameworks, from a UI perspective it doesn't make sense if they put ellipsis even if you have other page links. Isn't that's why it has the next, previous, first and last link pages on front and last links of the pagination so that users will know that there's more pages to navigate to?

Maybe this would help - https://www.dropbox.com/s/4vlxwf0as3kps2o/2018-03-05_0710.png?dl=0

taishi's avatar

So if for default it shows only 10 links, then by initial it should look like << 1 2 3 4 5 6 7 8 9 10 >>

The rest of the links should be shown when you try to click ">>" or hit a number that is above 5, so then it'll look like << 8 9 10 11 12 13 14 15 16 17 18 >> having number 13 as the current viewing page.

If the ellipsis are somewhat there to design for the viewer to see the last 2 pages of the link and if it cannot be removed, I might create something of mine.

Just for your reference, try searching something on google and use they're pagination. You'll notice that there aren't ellipsis at all considering that your search might have captured a million page links.

Like you said, its mostly sites who does it.

Thanks for your time.

jlrdw's avatar

Holly Molly you can write your own custom presenter, study them there docs.

HERE a custom presenter I wrote a while back

@if ($paginator->hasPages())
    <ul class="pagination pagination">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="disabled"><span>«</span></li>
        @else
            <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
        @endif

        @if($paginator->currentPage() > 3)
            <li class="hidden-xs"><a href="{{ $paginator->url(1) }}">1</a></li>
        @endif
        @if($paginator->currentPage() > 4)
            <li><span>...</span></li>
        @endif
        @foreach(range(1, $paginator->lastPage()) as $i)
            @if($i >= $paginator->currentPage() - 2 && $i <= $paginator->currentPage() + 2)
                @if ($i == $paginator->currentPage())
                    <li class="active"><span>{{ $i }}</span></li>
                @else
                    <li><a href="{{ $paginator->url($i) }}">{{ $i }}</a></li>
                @endif
            @endif
        @endforeach
        @if($paginator->currentPage() < $paginator->lastPage() - 3)
            <li><span>...</span></li>
        @endif
        @if($paginator->currentPage() < $paginator->lastPage() - 2)
            <li class="hidden-xs"><a href="{{ $paginator->url($paginator->lastPage()) }}">{{ $paginator->lastPage() }}</a></li>
        @endif

        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>
        @else
            <li class="disabled"><span>»</span></li>
        @endif
    </ul>
@endif

Again dig into those docs and API docs.

Notice the line

<li><span>...</span></li>

You can write whatever presenter you choose to.

taishi's avatar

Dude... As I have mentioned on my last comment, I might create something of mine. Dig into the comments...

rumm.an's avatar
php artisan vendor:publish --tag=laravel-pagination

This command will place the views in the resources/views/vendor/pagination directory. You can edit the file to your own taste. And still you you can use {{ $results->links() }} to generate the links.

taishi's avatar

Hi rumm.an, yeah. That's cool. Thanks!

Please or to participate in this conversation.