|
2 | 2 |
|
3 | 3 | namespace SkoreLabs\JsonApi; |
4 | 4 |
|
| 5 | +/** |
| 6 | + * @mixin \Illuminate\Database\Query\Builder |
| 7 | + */ |
5 | 8 | class Builder |
6 | 9 | { |
7 | | - /** |
8 | | - * Paginate the given query using Json API. |
9 | | - * |
10 | | - * @param array $columns |
11 | | - * |
12 | | - * @throws \InvalidArgumentException |
13 | | - * |
14 | | - * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
15 | | - */ |
16 | 10 | public function jsonPaginate() |
17 | 11 | { |
| 12 | + /** |
| 13 | + * Paginate the given query using JSON:API. |
| 14 | + * |
| 15 | + * @param int|string $perPage |
| 16 | + * @param array $columns |
| 17 | + * |
| 18 | + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator |
| 19 | + */ |
18 | 20 | return function ($perPage = null, $columns = ['*']) { |
19 | | - return function () use ($columns, $perPage) { |
20 | | - $perPage = $perPage ?: $this->model->getPerPage(); |
21 | | - $clientPerPage = (int) request('page.size', config('json-api.pagination.default_size')); |
| 21 | + $perPage = $perPage ?: $this->model->getPerPage(); |
| 22 | + $clientPerPage = (int) request('page.size', config('json-api.pagination.default_size')); |
| 23 | + |
| 24 | + if (!$perPage || $perPage < $clientPerPage) { |
| 25 | + $perPage = $clientPerPage; |
| 26 | + } |
22 | 27 |
|
23 | | - if (!$perPage || $perPage < $clientPerPage) { |
24 | | - $perPage = $clientPerPage; |
25 | | - } |
26 | | - |
27 | | - return $this->paginate($perPage, $columns, 'page[number]', (int) request('page.number')); |
28 | | - }; |
| 28 | + return $this->paginate($perPage, $columns, 'page[number]', (int) request('page.number')); |
29 | 29 | }; |
30 | 30 | } |
31 | 31 | } |
0 commit comments