Created
November 20, 2014 16:38
-
-
Save patrickmaciel/9a9b4c28f0e59e280ac6 to your computer and use it in GitHub Desktop.
Limit Paginator in Laravel 4.2
This file contains hidden or 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 | |
// The current page you're looking at, defaults to the first page. | |
$page = empty($inputs['page']) ? 1 : $inputs['page']; | |
// Number of records to display per page. | |
$per_page = 20; | |
// Total number of records to use for generating pages. This is now dynamic, so for anyone interested in anything beyond page 10, it will dynamically show 9 more pages if you click on page 10, until the end of the table. | |
$total = empty($inputs['quantidade']) ? 50 : $inputs['quantidade']; | |
$total = ($total - $per_page) + ($page * $per_page); | |
// Get the number of records per page, starting at the page number minus 1. Imagine you're looking at page 1, then it should skip 0 records. | |
$contatos = $contatos->take($per_page) | |
->skip(($page-1)*$per_page) | |
->orderBy('contatos.created_at', 'ASC') | |
->get(); | |
// Generate the pagination, passing in the results to be shown on the page, and use $total and $per_page to generate the pagination. | |
$contatos = \Paginator::make($contatos, $total, $per_page); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment