@if ($items->hasPages()) <div class="pagination-wrapper"> {{ $items->links() }} </div> @endif

laravel check pagination in blade

$category = Category::first(); $apps = $category->apps()->paginate(10); return view('example', compact('category', 'apps'));

paginate relationship laravel7

@foreach ($apps as $app) {{ $app->id }} @endforeach {!! $apps->render() !!}

paginate relationship laravel7

@if ($paginator->hasPages()) <ul class="pager"> @if ($paginator->onFirstPage()) <li class="disabled"><span>← Previous</span></li> @else <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">← Previous</a></li> @endif @foreach ($elements as $element) @if (is_string($element)) <li class="disabled"><span>{{ $element }}</span></li> @endif @if (is_array($element)) @foreach ($element as $page => $url) @if ($page == $paginator->currentPage()) <li class="active my-active"><span>{{ $page }}</span></li> @else <li><a href="{{ $url }}">{{ $page }}</a></li> @endif @endforeach @endif @endforeach @if ($paginator->hasMorePages()) <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">Next →</a></li> @else <li class="disabled"><span>Next →</span></li> @endif </ul> @endif

custom laravel pagination

<?php // config $link_limit = 7; // maximum number of links (a little bit inaccurate, but will be ok for now) ?> @if ($paginator->lastPage() > 1) <ul class="pagination"> <li class="{{ ($paginator->currentPage() == 1) ? ' disabled' : '' }}"> <a href="{{ $paginator->url(1) }}">First</a> </li> @for ($i = 1; $i <= $paginator->lastPage(); $i++) <?php $half_total_links = floor($link_limit / 2); $from = $paginator->currentPage() - $half_total_links; $to = $paginator->currentPage() + $half_total_links; if ($paginator->currentPage() < $half_total_links) { $to += $half_total_links - $paginator->currentPage(); } if ($paginator->lastPage() - $paginator->currentPage() < $half_total_links) { $from -= $half_total_links - ($paginator->lastPage() - $paginator->currentPage()) - 1; } ?> @if ($from < $i && $i < $to) <li class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }}"> <a href="{{ $paginator->url($i) }}">{{ $i }}</a> </li> @endif @endfor <li class="{{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }}"> <a href="{{ $paginator->url($paginator->lastPage()) }}">Last</a> </li> </ul> @endif

Laravel custom pagination

@if (isset($paginator) && $paginator->lastPage() > 1) <ul class="pagination"> <?php $interval = isset($interval) ? abs(intval($interval)) : 3 ; $from = $paginator->currentPage() - $interval; if($from < 1){ $from = 1; } $to = $paginator->currentPage() + $interval; if($to > $paginator->lastPage()){ $to = $paginator->lastPage(); } ?> <!-- first/previous --> @if($paginator->currentPage() > 1) <li> <a href="{{ $paginator->url(1) }}" aria-label="First"> <span aria-hidden="true">«</span> </a> </li> <li> <a href="{{ $paginator->url($paginator->currentPage() - 1) }}" aria-label="Previous"> <span aria-hidden="true">‹</span> </a> </li> @endif <!-- links --> @for($i = $from; $i <= $to; $i++) <?php $isCurrentPage = $paginator->currentPage() == $i; ?> <li class="{{ $isCurrentPage ? 'active' : '' }}"> <a href="{{ !$isCurrentPage ? $paginator->url($i) : '#' }}"> {{ $i }} </a> </li> @endfor <!-- next/last --> @if($paginator->currentPage() < $paginator->lastPage()) <li> <a href="{{ $paginator->url($paginator->currentPage() + 1) }}" aria-label="Next"> <span aria-hidden="true">›</span> </a> </li> <li> <a href="{{ $paginator->url($paginator->lastpage()) }}" aria-label="Last"> <span aria-hidden="true">»</span> </a> </li> @endif </ul> @endif

Laravel Pagination

Similar Code Examples