Commit acc27998 authored by Taylor Otwell's avatar Taylor Otwell

Move last page logic into Paginator class.

parent b933b19d
...@@ -47,11 +47,11 @@ class Paginator { ...@@ -47,11 +47,11 @@ class Paginator {
*/ */
public function __construct($results, $total, $per_page) public function __construct($results, $total, $per_page)
{ {
$this->page = static::page($total, $per_page);
$this->per_page = $per_page; $this->per_page = $per_page;
$this->results = $results; $this->results = $results;
$this->total = $total; $this->total = $total;
$this->page = static::page($this->last_page());
} }
/** /**
...@@ -60,11 +60,14 @@ class Paginator { ...@@ -60,11 +60,14 @@ class Paginator {
* The page will be validated and adjusted if it is less than 1 or * The page will be validated and adjusted if it is less than 1 or
* greater than the last page number. * greater than the last page number.
* *
* @param int $last_page * @param int $total
* @param int $per_page
* @return int * @return int
*/ */
public static function page($last_page) public static function page($total, $per_page)
{ {
$last_page = ceil($total / $per_page);
$page = Input::get('page', 1); $page = Input::get('page', 1);
if (is_numeric($page) and $page > $last_page) if (is_numeric($page) and $page > $last_page)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment