Skip to content

Instantly share code, notes, and snippets.

@hazeim254
Last active December 31, 2015 13:32
Show Gist options
  • Save hazeim254/14e95c8c1c9833dfc54f to your computer and use it in GitHub Desktop.
Save hazeim254/14e95c8c1c9833dfc54f to your computer and use it in GitHub Desktop.
Standard Laravel 5.x pagination partial
{{--$paginator Must be an instance of \Illuminate\Contracts\Pagination\LengthAwarePaginator--}}
@if ($paginator->lastPage() > 1)
<?php
$mod = 8;
/** @var \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator */
$page = $paginator->currentPage();
if ($paginator->lastPage() < $mod) {
$start = 1;
$last = $paginator->lastPage();
} elseif ($page < $mod) {
$start = 1;
$last = $mod;
} elseif ($page > $paginator->lastPage() - $mod) {
$start = $paginator->lastPage() - $mod + 1;
$last = $paginator->lastPage();
} else {
$start = $page - $mod / 2 + 1;
$last = $page + $mod / 2;
}
?>
<div class="text-center">
<ul class="pagination">
@if ($page > 1)
<li>
<a href="?page={{$page - 1}}"><i class="fa fa-chevron-left fa-fw"></i></a>
</li>
@endif
@for ($i = $start; $i <= $last; ++$i)
<li @if($page == $i)class="active"@endif>
<a href="?page={{$i}}">{{$i}}</a>
</li>
@endfor
@if ($page < $paginator->lastPage())
<li>
<a href="?page={{$page + 1}}"><i class="fa fa-chevron-right fa-fw"></i></a>
</li>
@endif
</ul>
</div>
@endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment