Skip to content

Instantly share code, notes, and snippets.

@pbelyaev
Last active March 31, 2017 20:51
Show Gist options
  • Save pbelyaev/bb65ad18f52fac34a9a09d6585b93501 to your computer and use it in GitHub Desktop.
Save pbelyaev/bb65ad18f52fac34a9a09d6585b93501 to your computer and use it in GitHub Desktop.
Laravel 5.3 - Pagination with custom URLs
// resources/views/pagination/default.blade.php
<ul class="pagination">
<!-- Previous Page Link -->
@if ($paginator->onFirstPage())
<li class="page-item disabled"><span class="page-link">&laquo;</span></li>
@else
<li class="page-item"><a class="page-link" href="{{ route($__env->yieldContent('route'), [ 'page' => $paginator->currentPage() - 1 ]) }}" rel="prev">&laquo;</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">&raquo;</a></li>
@else
<li class="page-item disabled"><span class="page-link">&raquo;</span></li>
@endif
</ul>
// resources/views/pagination/row.blade.php
@extends('pagination.default')
@section('route', 'rows:page')
// resources/views/rows.blade.php
@each('template', $rows, 'row')
{!! $rows->links('row-pagination') !!}
<?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