Skip to content

Commit

Permalink
Add configurable per page default
Browse files Browse the repository at this point in the history
  • Loading branch information
Torann committed Dec 17, 2018
1 parent 8e4dd72 commit d965b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/repositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
|--------------------------------------------------------------------------
*/

'per_page' => 50,
'max_per_page' => 100,

/*
Expand All @@ -30,5 +31,4 @@
*/

'cache_skip_param' => 'skipCache',

];
14 changes: 10 additions & 4 deletions src/Repositories/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit d965b74

Please sign in to comment.