diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 3c4aae4c4ecb..51447f2ecb28 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -482,14 +482,15 @@ public function lists($column, $key = null) */ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) { + $page = $page ?: Paginator::resolveCurrentPage($pageName); + + $perPage = $perPage ?: $this->model->getPerPage(); + $query = $this->toBase(); $total = $query->getCountForPagination(); - $results = $total ? $this->forPage( - $page = $page ?: Paginator::resolveCurrentPage($pageName), - $perPage = $perPage ?: $this->model->getPerPage() - )->get($columns) : []; + $results = $total ? $this->forPage($page, $perPage)->get($columns) : []; return new LengthAwarePaginator($results, $total, $perPage, $page, [ 'path' => Paginator::resolveCurrentPath(),