Skip to content

Commit

Permalink
Protect against division by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
datashaman committed Nov 3, 2017
1 parent 55b70a3 commit 1882167
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public function results()
$from = $this->from();
$perPage = $this->perPage();

// We can't let perPage of 0 through, it causes division by zero error in paginator.
if ($perPage === 0) {
$perPage = $results->count();
}

$currentPage = (! is_null($from) && ! empty($perPage)) ? $from / $perPage + 1 : null;

$this->attributes->put('results', new LengthAwarePaginator($results, $this->total(), $perPage, $currentPage));
Expand Down

0 comments on commit 1882167

Please sign in to comment.