Laravel pagination on steroids

dev-master 2019-01-26 08:08 UTC

This package is not auto-updated.

Last update: 2020-10-16 20:52:05 UTC


if use laravel4.0/laravel4.1/laravel4.2 click this:

This package is an extension for Laravel5 pagination module. Modified from desmart / pagination Thanks radmen

It provides new functionalities:

  • route based url generator
  • helpers for template render


To composer.json add: "thinkme/pagination": "dev-master" and then run composer update thinkme/pagination.


This package should not break compatibility with Laravel pagination module.

Laravel 5.0/5.1/5.2/5.3/5.4/5.5

Method overview

General usage

  • withQuery() - bind query parameters to url generator (by default query parameters are included). Works only for url generating from routes.
  • withoutQuery() - don't bind query parameters
  • route($route[, array $parameters]) - use given route for generating url to pages (it can be route name, or instance of Illuminate\Routing\Route)

For templates

  • pagesProximity($proximity) - set pages proximity
  • getPagesRange() - get list of pages to show in template (includes proximity)
  • canShowFirstPage() - check if can show first page (returns TRUE when first page is not in list generated by getPagesRange())
  • canShowLastPage() - check if can show last page (returns TRUE when last page is not in list generated by getPagesRange())

Example usage

In router

// example route (routes.php)
Route::get('list-{page}.html', ['as' => '', 'uses' => 'PhotoController@index']);

In controller

// IF use the current route
$list = new Paginator();
$list = list->make($item, $count, 1, $page, [
            'path' => Paginator::resolveCurrentPath(),

// or quick paginator
$query = User::select($columns);
$paginate = new Paginator();
$paginate->paginate($query, 10);//or $paginate->paginate($query, $perPage, $currentPage);
//or $list = $paginate ^#*&!^#*!^&*(!&#) You know;
//return $list
return $paginate;

//IF you do not want to use the default page name. Example: to
$paginate->paginate($query, $perPage, $currentPage, ['pageName' => 'p']);//

// IF use yourself Presenter Class
Paginator::presenter(function() use ($list) {
            return new MyPresenter($list);

In view

// list.blade.php

@foreach ($list as $item)
{{-- show item --}}

{!! $list->links('paginator') !!}

// if use yourself Presenter Class

{!! $list->render() !!}

// paginator.blade.php

@if ($paginator->lastPage() > 1)
  @foreach ($paginator->getPagesRange() as $page)
    {{ $page }}

// or this

@if ($paginator->lastPage() > 1)
    <div class="pagination">
            <a href="{{$paginator->url($paginator->currentPage()-1)}}" class="first"></a>
            <a href="javascript:;" class="first-none"></a>
            @foreach ($paginator->getPagesRange() as $page)
                    <span class="current">{{$page}}</span>
                    <a href="{{$paginator->url($page)}}">{{$page}}</a>
                <a href="{{$paginator->url($paginator->currentPage()+1)}}" class="last last-none"></a>
                <a href="javascript:;" class="last-none"></a>


This package is open-sourced software licensed under the MIT license