使用自定义模板分页 onEachSide 参数不起作用

With custom template pagination onEachSide parameter does not work

我laravel 8我设置onEachSide = 3:

    $nominated_photos_per_page= 14;
        $nominatedPhotos = PhotoNomination
            ...
            ->paginate($nominated_photos_per_page, array('*'), 'page', $page)
            ->onEachSide(3)

但它不起作用,我得到了从 1 到 20 的链接。

我使用自定义模板:

@if ($paginator->hasPages())

    <div class="forum-article__comments-pagination pagination">

        @if (!$paginator->onFirstPage())
        <a href="{{ $paginator->previousPageUrl() }}" class="pagination__nav pagination__nav--prev">
            <span>Предыдущая</span>
            <svg viewBox="0 0 19 8" xmlns="http://www.w3.org/2000/svg">
                <path d="M18.3536 4.35355C18.5488 4.15829 18.5488 3.84171 18.3536 3.64645L15.1716 0.464467C14.9763 0.269205 14.6597 0.269205 14.4645 0.464467C14.2692 0.65973 14.2692 0.976312 14.4645 1.17157L17.2929 4L14.4645 6.82843C14.2692 7.02369 14.2692 7.34027 14.4645 7.53554C14.6597 7.7308 14.9763 7.7308 15.1716 7.53554L18.3536 4.35355ZM-4.37114e-08 4.5L18 4.5L18 3.5L4.37114e-08 3.5L-4.37114e-08 4.5Z"></path>
            </svg>
        </a>
        @endif

        <ul class="pagination__list">

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

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


        @if ($paginator->hasMorePages())
        <a href="{{ $paginator->nextPageUrl() }}" class="pagination__nav pagination__nav--next">
            <span>Следующая</span>
            <svg viewBox="0 0 19 8" xmlns="http://www.w3.org/2000/svg">
                <path d="M18.3536 4.35355C18.5488 4.15829 18.5488 3.84171 18.3536 3.64645L15.1716 0.464467C14.9763 0.269205 14.6597 0.269205 14.4645 0.464467C14.2692 0.65973 14.2692 0.976312 14.4645 1.17157L17.2929 4L14.4645 6.82843C14.2692 7.02369 14.2692 7.34027 14.4645 7.53554C14.6597 7.7308 14.9763 7.7308 15.1716 7.53554L18.3536 4.35355ZM-4.37114e-08 4.5L18 4.5L18 3.5L4.37114e-08 3.5L-4.37114e-08 4.5Z"></path>
            </svg>
        </a>
        @endif

    </div>


@endif

我想知道是不是这个模板有问题,我需要在里面修改什么?

看来自定义模板没有这个问题。

如果设置

$nominated_photos_per_page= 2;

我有分页

1-20..89-90

当当前页为 3 且请求有 180 行时($nominated_photos_per_page= 2 为 90 页)

并且我有控制权:

          ->paginate($nominated_photos_per_page, array('*'), 'page', $page)
           ->onEachSide(3)

我还在模板中添加了这个参数:

        {{ $nominatedPhotosPagination->onEachSide(3)->links() }}

但是如果设置 $nominated_photos_per_page= 14;

我有分页 1..13(180 行)完全没有我预期的间隙,我看到调试分页对象:

[next_page_url] => http://127.0.0.1:8000/nomination/get_cities_selection_array?page=2
[path] => http://127.0.0.1:8000/nomination/get_cities_selection_array
[per_page] => 14
[prev_page_url] => 
[to] => 14
[total] => 180

我不明白它是如何工作的...

分页器 class 位于何处?我可以调试源代码吗?

谢谢!

我查看了分页器的源代码并决定不使用 onEachSide 方法,而是在模板中制作我需要的所有逻辑 bootstrap-4.blade.php 代码:

@if ($paginator->hasPages())
<?php
$items_count = 3;
$show_first_item = false;
$show_last_item = false;

$limit_start= 1;
$limit_end= 1;
if (count($elements[0]) > $items_count*2) {
    $limit_start= $paginator->currentPage() - 1;
    $limit_end= $limit_start + 2;
}

if($paginator->currentPage() >= $items_count) {
    $show_first_item= true;
}
if($paginator->lastPage() > $paginator->currentPage() + 1) {
    $show_last_item= true;
}
?>
<div class="forum-article__comments-pagination pagination">

    @if (!$paginator->onFirstPage())
    <a href="{{ $paginator->previousPageUrl() }}" class="pagination__nav pagination__nav--prev">
        <span>Предыдущая</span>
        <svg viewBox="0 0 19 8" xmlns="http://www.w3.org/2000/svg">
            <path d="M18.3536 4.35355C18.5488 4.15829 18.5488 3.84171 18.3536 3.64645L15.1716 0.464467C14.9763 0.269205 14.6597 0.269205 14.4645 0.464467C14.2692 0.65973 14.2692 0.976312 14.4645 1.17157L17.2929 4L14.4645 6.82843C14.2692 7.02369 14.2692 7.34027 14.4645 7.53554C14.6597 7.7308 14.9763 7.7308 15.1716 7.53554L18.3536 4.35355ZM-4.37114e-08 4.5L18 4.5L18 3.5L4.37114e-08 3.5L-4.37114e-08 4.5Z"></path>
        </svg>
    </a>
    @endif

    <ul class="pagination__list">


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

        {{-- Array Of Links --}}
        @if (is_array($element))

        @foreach ($element as $page => $url)

        @if($show_first_item and $page == 1)
        <li class=""><a class="" href="{{ $url }}">{{ $page }}</a></li>
        @if($paginator->currentPage()!= 3)
        <li class="disabled"><a class="">...</a></li>
        @endif
        @endif

        @if($page >= $limit_start and $page <= $limit_end)
        @if ($page == $paginator->currentPage())
        <li class="active"><a href=""><span class="">{{ $page }}</span></a></li>
        @else
        <li class=""><a class="" href="{{ $url }}">{{ $page }}</a></li>
        @endif
        @endif

        @if($show_last_item and $page == $paginator->lastPage())
        @if($paginator->currentPage()!= $paginator->lastPage()-2)
        <li class="disabled"><a class="">...</a></li>
        @endif
        <li class=""><a class="" href="{{ $url }}">{{ $page }}</a></li>
        @endif

        @endforeach

        @endif
        @endforeach
    </ul>


    @if ($paginator->hasMorePages())
    <a href="{{ $paginator->nextPageUrl() }}" class="pagination__nav pagination__nav--next">
        <span>Следующая</span>
        <svg viewBox="0 0 19 8" xmlns="http://www.w3.org/2000/svg">
            <path d="M18.3536 4.35355C18.5488 4.15829 18.5488 3.84171 18.3536 3.64645L15.1716 0.464467C14.9763 0.269205 14.6597 0.269205 14.4645 0.464467C14.2692 0.65973 14.2692 0.976312 14.4645 1.17157L17.2929 4L14.4645 6.82843C14.2692 7.02369 14.2692 7.34027 14.4645 7.53554C14.6597 7.7308 14.9763 7.7308 15.1716 7.53554L18.3536 4.35355ZM-4.37114e-08 4.5L18 4.5L18 3.5L4.37114e-08 3.5L-4.37114e-08 4.5Z"></path>
        </svg>
    </a>
    @endif

</div>

@endif

它有助于制作我需要的分页链接。