feat: add multi-tenant controllers for catalog and tenant management and implement pagination macro in AppServiceProvider
This commit is contained in:
@@ -19,6 +19,22 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
\Illuminate\Database\Eloquent\Builder::macro('paginateFromRequest', function (int $defaultPerPage = 15, int $maxPerPage = 100, ?int $page = null) {
|
||||
/** @var \Illuminate\Database\Eloquent\Builder $this */
|
||||
$perPage = (int) request()->query('per_page', $defaultPerPage);
|
||||
$page = $page ?? (int) request()->query('page', 1);
|
||||
|
||||
if ($perPage <= 0) {
|
||||
$perPage = $defaultPerPage;
|
||||
}
|
||||
if ($perPage > $maxPerPage) {
|
||||
$perPage = $maxPerPage;
|
||||
}
|
||||
if ($page <= 0) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
return $this->paginate(perPage: $perPage, page: $page);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user