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

Crazylife's avatar

How to limit the link of pagination to be displayed?

I want to show less page link for the pagination, by default it looks like

< 1 2 3 4 5 6 7 8 ... 100 101 >
< 1 2 ... 8 9 10 11 12 13 14 ... 100 101 >

How can i make it in this way?

< 1 2 3 4 5 ... 101 >
< 1 ... 8 9 10 11 ...101 >

This is my code

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

        {{-- Pagination Elements --}}
        @foreach ($elements as $element)
            {{-- "Three Dots" Separator --}}
            @if (is_string($element))
                <li class="page-item disabled"><span class="page-link">{{ $element }}</span></li>
            @endif

            {{-- Array Of Links --}}
            @if (is_array($element))
                @foreach ($element as $page => $url)
                    @if ($page == $paginator->currentPage())
                        <li class="page-item active"><span class="page-link">{{ $page }}</span></li>
                    @else
                        <li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
                    @endif
                @endforeach
            @endif
        @endforeach

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

How can i achieve the desired output as i stated? Thanks.

0 likes
4 replies
diegoaurino's avatar

Hello, @crazylife !

Inside the {{-- Pagination Elements --}} loop, you can create a statement to skip those elements or range of elements you don't want to display.

YeZawHein's avatar

@crazylife Laravel 5.7 has a new pagination method to customize the number of links on each side of the paginator.

{{ $elements->onEachSide(3)->links() }}
//display three links on both sides of current page 7
  

//Output

1 2 .. 4 5 6 7 8 9 10 .. 25 26

Please or to participate in this conversation.