initial version of pagination library.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<?php namespace System\DB;
|
||||
|
||||
use System\DB;
|
||||
use System\Config;
|
||||
use System\Str;
|
||||
use System\Config;
|
||||
|
||||
class Query {
|
||||
|
||||
@@ -447,6 +447,25 @@ class Query {
|
||||
return $this->first()->aggregate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paginated query results.
|
||||
*
|
||||
* @param int $per_page
|
||||
* @return Paginator
|
||||
*/
|
||||
public function paginate($per_page)
|
||||
{
|
||||
$total = $this->count();
|
||||
|
||||
// Reset the SELECT clause so we can execute another query to get the results.
|
||||
$this->select = null;
|
||||
|
||||
// Get the current page from the Paginator. The Paginator class will validate the page number.
|
||||
$page = \System\Paginator::page(ceil($total / $per_page));
|
||||
|
||||
return new \System\Paginator($this->skip(($page - 1) * $per_page)->take($per_page)->get(), $total, $per_page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an INSERT statement.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user