我目前正在使用Laravel 5.3,想知道是否可以自定义“三点”销毁器。 (跳过第9-10页,这太晚了)

Example

当前,如果有11个以上的页面,则将启动三个点...如果您的站点响应迅速,这不是安静的方法。如果有很多页面,则分为两行。

Example2

我找不到关于$ resource-> links()选项的任何信息。但是,如果有请告诉我!非常感激。

编辑:它与以下功能有关:
供应商/laravel/framework/src/Illuminate/Pagination/LengthAwarePaginator.php(第128页,render())。当前函数不支持第二个变量。所以我想我必须重建它?

最佳答案

这是Laravel 5.5+的解决方案。这是它的作用:

  • 显示第一页和最后一页。
  • 显示当前页面的前一页和后两页。
  • 当前页面大于4之后,左侧仅出现三个点。
  • 当前页面小于4-(页面数)后,仅在右侧显示三个点。

  • <!-- 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
    

    输出:

    Page 1 (first page)

    Page 3

    Page 10 (last page)

    关于php - Laravel分页 "Three Dots"分隔符自定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39520825/

    10-12 12:46
    查看更多