Created
March 21, 2019 08:03
-
-
Save georgebent/9823c701ff53a9fdb584b5203851aa48 to your computer and use it in GitHub Desktop.
Custom Laravel Paginator
This file contains 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
@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 |
This file contains 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
@include('pagination', ['paginator' => $users, 'interval' => 5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment