Skip to content

Commit

Permalink
Add paginateRaw method to Builder class
Browse files Browse the repository at this point in the history
  • Loading branch information
karamqubsi committed Aug 25, 2017
1 parent 60a55e8 commit e47dfa6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,21 @@ public function get()
* @param int $perPage
* @param string $pageName
* @param int|null $page
* @param bool $isRaw
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $pageName = 'page', $page = null)
public function paginate($perPage = null, $pageName = 'page', $page = null, $isRaw = false)
{
$engine = $this->engine();

$page = $page ?: Paginator::resolveCurrentPage($pageName);

$perPage = $perPage ?: $this->model->getPerPage();

$results = Collection::make($engine->map(
$rawResults = $engine->paginate($this, $perPage, $page), $this->model
));
$rawResults = $engine->paginate($this, $perPage, $page);
$results = $isRaw ? $rawResults :
Collection::make($engine->map(
$rawResults, $this->model
)) ;

$paginator = (new LengthAwarePaginator($results, $engine->getTotalCount($rawResults), $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
Expand All @@ -200,6 +202,16 @@ public function paginate($perPage = null, $pageName = 'page', $page = null)
return $paginator->appends('query', $this->query);
}

/**
* Paginate the given query into a raw data paginator.
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginateRaw()
{
return $this->paginate($perPage = null, $pageName = 'page', $page = null, $isRaw = true);
}

/**
* Get the engine that should handle the query.
*
Expand Down

0 comments on commit e47dfa6

Please sign in to comment.