Skip to content
Advertisement

In Laravel Pagination how to add first page and last page?

In Laravel 8 pagination how to show less number of pages and also how to add “First Page” and “Last Page”

Now in Laravel when we have more data, it will show the pagination like this: Laravel 8 Pagination

But I want my pagination to be like the images given below:

Desired Pagination Sample

Or

Desired Pagination Sample

Advertisement

Answer

To customizing the pagination view, run below command in console

php artisan vendor:publish --tag=laravel-pagination

in /resources/views/vendor/pagination/bootstrap-4.blade.php add bellow code.

<ul class="pagination">
    @if ($paginator->onFirstPage())
        <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.first')">
            <span class="page-link" aria-hidden="true">&laquo;</span>
        </li>
    @else
        <li class="page-item">
            <a class="page-link" href="{{ Request::url() }}" rel="prev" aria-label="@lang('pagination.first')">&laquo;</a>
        </li>
    @endif

    ...

    @if ($paginator->hasMorePages())
        <li class="page-item">
            <a class="page-link" href="{{ Request::url().'?page='.$paginator->lastPage() }}" rel="last" aria-label="@lang('pagination.last')">&raquo;</a>
        </li>
    @else
        <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.last')">
            <span class="page-link" aria-hidden="true">&raquo;</span>
        </li>
    @endif
</ul>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement