Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bboypluss's avatar

hide fields in paginator

Hi everyone. I've implemented the default paginator of laravel.

collectionName->paginate($numberPerPage).

All is good. I receive the response:

"current_page": 1, "data":[ all data here], "first_page_url": "http://homestead.test/api/user/orders?page=1", "from": 1, "last_page": 2, "last_page_url": "http://homestead.test/api/user/orders?page=2", "next_page_url": "http://homestead.test/api/user/orders?page=2", "path": "http://homestead.test/api/user/orders", "per_page": 5, "prev_page_url": null, "to": 5, "total": 10

Now i want to hide some fields which i not use, such us first_page_url and others. How can i do ?? I want to do this every time i call the function paginate().

Thank you for your time.

0 likes
4 replies
andreich1980's avatar

why would you hide them? try using ->simplePaginate($numberPerPage) maybe?

bboypluss's avatar

I don't need them in the front end. I want to optimize to the best the system. I know that are only bytes but i want to save space as much as possible.

jlrdw's avatar

First, I have no idea why you would want to hide a pagination link. But you can write any pagination template you need, you are free to do that. The docs under pagination explains it,

As example here is a custom template I use:

@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

But you need to on your own learn css (not a library) and you will discover how to handle things like you ask. A pagination link is just that, a link with css style applied.

If you don't want extra links, as suggested use simple paginate.

DiogoGomes's avatar

If you really just want the list of items back you can: collectionName->paginate($numberPerPage)->items()

that will get you only the array of the collection items

1 like

Please or to participate in this conversation.