Skip to content

Commit

Permalink
Merge pull request #16547 from vlakoff/empty-pages
Browse files Browse the repository at this point in the history
[5.3] Create custom Collection also on empty page
  • Loading branch information
taylorotwell authored Nov 25, 2016
2 parents 42767b2 + 7aa3002 commit bd3eb57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',

$total = $query->getCountForPagination();

$results = $total ? $this->forPage($page, $perPage)->get($columns) : new Collection;
$results = $total
? $this->forPage($page, $perPage)->get($columns)
: $this->model->newCollection();

return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $p

$total = $this->getCountForPagination($columns);

$results = $total ? $this->forPage($page, $perPage)->get($columns) : [];
$results = $total ? $this->forPage($page, $perPage)->get($columns) : collect();

return new LengthAwarePaginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
Expand Down

0 comments on commit bd3eb57

Please sign in to comment.