diff --git a/config/repositories.php b/config/repositories.php index 561caa2..ff430e2 100644 --- a/config/repositories.php +++ b/config/repositories.php @@ -8,6 +8,7 @@ |-------------------------------------------------------------------------- */ + 'per_page' => 50, 'max_per_page' => 100, /* @@ -30,5 +31,4 @@ */ 'cache_skip_param' => 'skipCache', - ]; \ No newline at end of file diff --git a/src/Repositories/AbstractRepository.php b/src/Repositories/AbstractRepository.php index 871c9c7..761dade 100755 --- a/src/Repositories/AbstractRepository.php +++ b/src/Repositories/AbstractRepository.php @@ -491,6 +491,9 @@ public function pluck($value, $key = null) */ public function paginate($per_page = null, $columns = ['*'], $page_name = 'page', $page = null) { + // Get the default per page when not set + $per_page = $per_page ?: config('repositories.per_page', 15); + // Get the per page max $per_page_max = config('repositories.max_per_page', 100); @@ -508,18 +511,21 @@ public function paginate($per_page = null, $columns = ['*'], $page_name = 'page' /** * Retrieve all data of repository, paginated * - * @param int $perPage + * @param int $per_page * @param array $columns - * @param string $pageName + * @param string $page_name * @param int|null $page * * @return \Illuminate\Contracts\Pagination\Paginator */ - public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null) + public function simplePaginate($per_page = null, $columns = ['*'], $page_name = 'page', $page = null) { $this->newQuery(); - return $this->query->simplePaginate($perPage, $columns, $pageName, $page); + // Get the default per page when not set + $per_page = $per_page ?: config('repositories.per_page', 15); + + return $this->query->simplePaginate($per_page, $columns, $page_name, $page); } /**