Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit e41fe43

Browse files
committed
Add integration to hammerstone/fast-paginate
1 parent 5376f92 commit e41fe43

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"laravel-pint.enable": true,
3+
"editor.formatOnSave": true
4+
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [3.2.8] - 2022-08-26
11+
12+
### Added
13+
14+
- Support for [hammerstone/fast-paginate](https://github.com/hammerstonedev/fast-paginate)
15+
1016
## [3.2.7] - 2022-07-15
1117

1218
### Fixed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"phpunit/phpunit": "^7.0|^9.0"
2727
},
2828
"suggest": {
29+
"hammerstone/fast-paginate": "Improves jsonApiPaginate method performance (SQL database query pagination)",
2930
"skorelabs/laravel-query-builder": "Allows to include data on your API responses following the JSON:API"
3031
},
3132
"autoload": {

src/Builder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ public function jsonPaginate()
1717
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
1818
*/
1919
return function ($perPage = null, $columns = ['*']) {
20+
$pageNumberKey = 'page[number]';
21+
$pageNumber = (int) request('page.number');
2022
$perPage = $perPage ?: $this->model->getPerPage();
2123
$clientPerPage = (int) request('page.size', config('json-api.pagination.default_size'));
2224

2325
if (! $perPage || $perPage < $clientPerPage) {
2426
$perPage = $clientPerPage;
2527
}
2628

27-
return $this->paginate($perPage, $columns, 'page[number]', (int) request('page.number'));
29+
if (class_exists("Hammerstone\FastPaginate\FastPaginate")) {
30+
return $this->fastPaginate($perPage, $columns, $pageNumberKey, $pageNumber);
31+
}
32+
33+
return $this->paginate($perPage, $columns, $pageNumberKey, $pageNumber);
2834
};
2935
}
3036
}

0 commit comments

Comments
 (0)