Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@carloscarucce
Last active January 27, 2023 03:10
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save carloscarucce/33f6082d009c20f77499252b89c35dea to your computer and use it in GitHub Desktop.
Save carloscarucce/33f6082d009c20f77499252b89c35dea to your computer and use it in GitHub Desktop.
Pagination template for laravel 5
@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">&laquo;</span>
</a>
</li>
<li>
<a href="{{ $paginator->url($paginator->currentPage() - 1) }}" aria-label="Previous">
<span aria-hidden="true">&lsaquo;</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">&rsaquo;</span>
</a>
</li>
<li>
<a href="{{ $paginator->url($paginator->lastpage()) }}" aria-label="Last">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
@endif
</ul>
@endif
@fhefh2015
Copy link

nice, work well, Thanks!

@kk5949
Copy link

kk5949 commented May 16, 2019

It's appropriate for me. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment