Last active
December 31, 2015 13:32
-
-
Save hazeim254/14e95c8c1c9833dfc54f to your computer and use it in GitHub Desktop.
Standard Laravel 5.x pagination partial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{--$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