From 1882167ecbc6fed55336655168b47ed97a15785a Mon Sep 17 00:00:00 2001 From: datashaman Date: Fri, 3 Nov 2017 23:24:09 +0200 Subject: [PATCH] Protect against division by zero --- src/Response.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Response.php b/src/Response.php index cc63c6e..43512e6 100644 --- a/src/Response.php +++ b/src/Response.php @@ -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));