Three-Point Separator Configuration

I am currently using Laravel 5.3 and wondered if there is an option to configure the Detector with three points. (skips page 9-10, which ends)

Example

Currently, three dots are triggered if there are more than 11 pages. Which is not so useful if your site is responsive. if there are up to many pages, so it is split into 2 lines.

Example 2

I can not find anything that there are options for $ resource-> links (). But if there is, please tell me! Very much appreciated.

Edit: this is due to the following function: vendor / laravel / framework / src / Illuminate / Pagination / LengthAwarePaginator.php (page: 128, render ()). The current function does not support the second variable. So I probably need to rebuild it?

+4
source share
2 answers

This solution is for Laravel 5. 5+. Here is what he does:

  • Shows the first and last page.
  • Shows the previous and next two pages from the current page.
  • Three dots appear on the left only after the current page is greater than 4.
  • Three dots appear on the right only after the current page is less than 4 - (number of pages).
<!-- Pagination Elements -->
@foreach ($elements as $element)
    <!-- Array Of Links -->
    @foreach ($element as $page => $url)
        <!--  Use three dots when current page is greater than 4.  -->
        @if ($paginator->currentPage() > 4 && $page === 2)
            <li class="page-item disabled"><span class="page-link">...</span></li>
        @endif

        <!--  Show active page else show the first and last two pages from current page.  -->
        @if ($page == $paginator->currentPage())
            <li class="page-item active"><span class="page-link">{{ $page }}</span></li>
        @elseif ($page === $paginator->currentPage() + 1 || $page === $paginator->currentPage() + 2 || $page === $paginator->currentPage() - 1 || $page === $paginator->currentPage() - 2 || $page === $paginator->lastPage() || $page === 1)
            <li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
        @endif

        <!--  Use three dots when current page is away from end.  -->
        @if ($paginator->currentPage() < $paginator->lastPage() - 3 && $page === $paginator->lastPage() - 1)
            <li class="page-item disabled"><span class="page-link">...</span></li>
        @endif
    @endforeach
@endforeach

Output:

Page 1 (first page)

Page 3

Page 10 (last page)

+2
source

, artistan PHP-: , , , custom.blade.php :

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

    {{-- Pagination Elements --}}
    @foreach ($elements as $element)
        {{-- Array Of Links --}}
        @if (is_array($element))
            @foreach ($element as $page => $url)
                @if ($page === $paginator->currentPage())
                    <li class="active pageNumber"><span>{{ $page }}</span></li>
                @elseif (($page === $paginator->currentPage() + 1 || $page === $paginator->currentPage() + 2)
                 || $page === $paginator->lastPage())
                    <li><a class="pageNumber" href="{{ $url }}">{{ $page }}</a></li>
                @elseif ($page === $paginator->lastPage()-1)
                    <li class="disabled"><span>...</span></li>
                @endif
            @endforeach
        @endif
    @endforeach

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

{{- Array Of Links -}}. , , , .

:

<div class="pagination">
    @if ($users instanceof \Illuminate\Pagination\LengthAwarePaginator)
        {{ $users->links('vendor.pagination.custom') }}
    @endif
</div>
+1

Source: https://habr.com/ru/post/1654748/


All Articles