-
Notifications
You must be signed in to change notification settings - Fork 0
Pagination
plokko edited this page Mar 23, 2020
·
1 revision
To enable pagination edit the $paginate protected propriety or via the pagination() method setting it to the wanted page size or to null to disable it.
class TestQuerableResource extends \Plokko\QuerableResource\QuerableResource {
protected
$paginate = 30,//30 items per page
/**
* Allowed client-defined paginations,
* if null no client pagination is allowed
* if int set the maxium page size allowed
* if array only the page sizes listed in the array are allowed
* @var int|array|null
*/
$paginations = 100;
protected function getQuery(): Illuminate\Database\Eloquent\Builder
{
return App\User::where('id','>',1); // Just a simple query to demonstrate functionality
}
}
The propriety $paginations specify the user-selectable available values, if the value is null
only $paginate user values will be discarted in favor of $paginate, if an int value is specified it will be set as the maxium value (in this case the user could select pagination up to 100 with default of 30 items per page); if an array (of integers) is specified the user value must be contained in the array or $paginate value will be used (ex. [10,20,30,50]
)
Route::get('/test',function(){
$qr = new TestQuerableResource();
$qr->paginate(10); // Set pagination to 10 items per page
return $qr;
});