Generate the HTML for paginating your tables

[Since 0.7.2]


With Pletfix's paginator, you can simply paginate database tables and other lists.

Paginator - Slider at the left site Paginator - Slider in the middle Paginator - Slider at the right site

Basic Usage

You may use the paginator function to create a new Paginator instance:

$paginator = paginator($total, $limit);

The first argument passed to the paginate method is the total number of items. The second argument specified the maximum of items you would like displayed "per page". You may also set the current page as third argument, but, of course, this value is automatically detected.

Limit the Source

The following example illustrates a typical use case with a Query Builder into a controller action method:

public function index()
    $builder   = User::builder();
    $paginator = paginator($builder->count(), 10);
    $users     = $builder

    return view('users.index', compact('paginator', 'users'));

In this example we have specify that we would like to display 10 user accounts per page. The view 'users.index' have to include a partial view to render the paginator control, for example:



    <div class="table-responsive">
        <!-- show table data -->


Render the Paginator

The Pletfix Application Skeleton has already placed the partial view _pagination.blade.php in the view directory to rendering the pagination control. The partial view is compatible with the Bootstrap CSS framework. Feel free to customize this as you wish.

@if ($paginator->hasMultiplePages())
    <ul class="pagination">
        @if ($url = $paginator->previousUrl())
            <li><a href="{{$url}}" title="previous"><span>&laquo;</span></a></li>
            <li class="disabled"><span>&laquo;</span></li>
        @foreach ($paginator->pages() as $page)
            @if($page == '...')
                <li class="disabled"><span>...</span></li>
            @elseif ($page == $paginator->currentPage())
                <li class="active"><span>{{$page}}</span></li>
                <li><a href="{{$paginator->url($page)}}">{{$page}}</a></li>
        @if ($url = $paginator->nextUrl())
            <li><a href="{{$url}}" title="next"><span>&raquo;</span></a></li>
            <li class="disabled"><span>&raquo;</span></li>

As shown above, you may include this partial in your view with the @include directive:


Of course, if the paginator is not stored in the $paginator variable, you have to passed this one as the second argument:

@include('_pagination', ['paginator' => $myPaginator])

Available Methods

Method Listing


The currentPage method gets the current page.

$currentPage = $paginator->currentPage();


The getFragment method gets the URL fragment.

$fragment = $paginator->getFragment();


The getPageKey method gets the query string variable used to store the page.

$key = $paginator->getPageKey();


The getParameters method gets the query parameters.

$params = $paginator->getParameters();    


The hasMultiplePages method determines if there are enough items to split into multiple pages.

$canPaginate = $paginator->hasMultiplePages();  


The lastPage method gets the last page.

$canPaginate = $paginator->lastPage();  


The limit method gets the maximal number of items per page.

$limit = $paginator->limit();  


The nextUrl method gets the URL for the next page.

$canPaginate = $paginator->nextUrl();  


The offset method gets the offset of items for the current page.

$offset = $paginator->offset();  


The pages method gets the pages.

$pages = $paginator->pages(); // e.g. [1, 2, '...', 5, 6, 7, 8, 9, 10, 11, '...', 14, 15]


The previousUrl method gets the URL for the previous page.

$prevUrl = $paginator->previousUrl();  


The setFragment method sets a URL fragment to add to all URLs.



The setPageKey method sets the query string variable used to store the page.



The setParameters method sets a query parameters to add to all URLs.

$paginator->setParameters(['foo' => 'bar']);  


The total method gets the total number of items.

$total = $paginator->total();  


The url method gets the URL for a given page number.

┬žurl = $paginator->url(3);  

(edit on GitHub)