I laravel 8 I set onEachSide = 3:
$nominated_photos_per_page= 14;
$nominatedPhotos = PhotoNomination
...
->paginate($nominated_photos_per_page, array('*'), 'page', $page)
->onEachSide(3)
but it does not work and I got links from 1 till 20.
I use custom template :
@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
I wonder is it issue with this template and what have I to modify in it ?
Looks like this problem is not with custom template.
If to set
$nominated_photos_per_page= 2;
I have pagination
1-20..89-90
When current page is 3 and request has 180 rows(90 pages for $nominated_photos_per_page= 2)
and in control I have :
->paginate($nominated_photos_per_page, array('*'), 'page', $page)
->onEachSide(3)
Also I aded this parameter in template :
{{ $nominatedPhotosPagination->onEachSide(3)->links() }}
But if to set $nominated_photos_per_page= 14;
I have pagionation 1..13 (for 180 rows) no gaps as I expected at all, and debugging pagination object I see :
[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
I do not understand how it works...
Where paginator class is located? Can I debug it source?
Thanks!
I reviewed source of paginator and decided not to use onEachSide method , but to make all logic I need in template bootstrap-4.blade.php with code :
@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
It helped to make pagination links I need.