Last active
March 31, 2017 20:51
-
-
Save pbelyaev/bb65ad18f52fac34a9a09d6585b93501 to your computer and use it in GitHub Desktop.
Laravel 5.3 - Pagination with custom URLs
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
// resources/views/pagination/default.blade.php | |
<ul class="pagination"> | |
<!-- Previous Page Link --> | |
@if ($paginator->onFirstPage()) | |
<li class="page-item disabled"><span class="page-link">«</span></li> | |
@else | |
<li class="page-item"><a class="page-link" href="{{ route($__env->yieldContent('route'), [ 'page' => $paginator->currentPage() - 1 ]) }}" rel="prev">«</a></li> | |
@endif | |
<!-- Pagination Elements --> | |
@foreach ($elements as $element) | |
<!-- "Three Dots" Separator --> | |
@if (is_string($element)) | |
<li class="page-item disabled"><span class="page-link">{{ $element }}</span></li> | |
@endif | |
<!-- Array Of Links --> | |
@if (is_array($element)) | |
@foreach ($element as $page => $url) | |
@if ($page == $paginator->currentPage()) | |
<li class="page-item active"><span class="page-link">{{ $page }}</span></li> | |
@else | |
<li class="page-item"><a class="page-link" href="{{ route($__env->yieldContent('route'), [ 'page' => $page ]) }}">{{ $page }}</a></li> | |
@endif | |
@endforeach | |
@endif | |
@endforeach | |
<!-- Next Page Link --> | |
@if ($paginator->hasMorePages()) | |
<li class="page-item"><a class="page-link" href="{{ route($__env->yieldContent('route'), [ 'page' => $paginator->currentPage() + 1 ]) }}" rel="next">»</a></li> | |
@else | |
<li class="page-item disabled"><span class="page-link">»</span></li> | |
@endif | |
</ul> |
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
// resources/views/pagination/row.blade.php | |
@extends('pagination.default') | |
@section('route', 'rows:page') |
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
// resources/views/rows.blade.php | |
@each('template', $rows, 'row') | |
{!! $rows->links('row-pagination') !!} |
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
<?php | |
// routes/web.php | |
Route::get('/', function (App\Rows $rows) { | |
return view('rows')->with('rows', $rows->paginate()); | |
})->name('rows'); | |
Route::get('page/{page}', function (App\Rows $rows, $page = 1) { | |
return view('rows')->with('rows', $rows->paginate(null, null, null, $page)); | |
})->name('rows:page'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment