how to use pagination in laravel code example
Example 1: laravel pagination
{{ $users->withQueryString()->links() }}
Example 2: laravel pagination
DB::table('users') -> paginate(15)
Example 3: Laravel 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();
}
?>
<!
@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
<!
@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
<!
@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
Example 4: custom laravel pagination
@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