Scramble 0.12.x is here! Manual parameter docs, transformers API and more.
Learn more

Laravel JSON API Paginate

On this page
Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data, Laravel Query Builder, and other packages.

Spatie’s Laravel JSON API Paginate is a great and simple package that adds support for JSON:API compliant query parameters for pagination.

Scramble has Laravel JSON API Paginate support as part of the Scramble PRO package. You can get Scramble PRO here: https://scramble.dedoc.co/pro. After purchasing, you will receive the license key via email.

Installation

Installation instructions for `dedoc/scramble-pro`

Usage

Whenever you use the jsonPaginate method, Scramble adds page[size] and page[number] query parameters to the documentation.

use App\Models\Job;
class JobsController extends Controller
{
public function index()
{
return Job::query()->jsonPaginate();
}
}
Resulting documentation
jobs.index
get
https://bestjobs.app/api/jobs
Request
query Params
page[size]
integer
The number of results that will be returned per page.
Default
30
page[number]
integer
The page number to start the pagination from.

If you’ve published the spatie/laravel-json-api-paginate config and customized the JSON paginate method name or parameter names, Scramble will document that according to your configuration:

<?php
return [
// ..... other config options .....
/*
* The key of the page[x] query string parameter for page number.
*/
'number_parameter' => 'number',
'number_parameter' => 'num',
/*
* The key of the page[x] query string parameter for page size.
*/
'size_parameter' => 'size',
'size_parameter' => 'amount',
// ..... other config options .....
];
Resulting documentation
jobs.index
get
https://bestjobs.app/api/jobs
Request
query Params
page[amount]
integer
The number of results that will be returned per page.
Default
30
page[num]
integer
The page number to start the pagination from.

You can modify the default page size by either changing the configuration parameter or by passing the number to the jsonPaginate method. Scramble will document the correct default page size in both cases.

Cursor pagination

If you have enabled cursor pagination, Scramble will document the page[cursor] query parameter.

<?php
return [
// ..... other config options .....
/*
* The key of the page[x] query string parameter for cursor.
*/
'cursor_parameter' => 'cursor',
/*
* If you want to cursor pagination, set this to true.
* This would override use_simple_pagination.
*/
'use_cursor_pagination' => true,
// ..... other config options .....
];
Resulting documentation
jobs.index
get
https://bestjobs.app/api/jobs
Request
query Params
page[cursor]
string
The cursor to start the pagination from.
page[size]
integer
The number of results that will be returned per page.
Default
30
Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data, Laravel Query Builder, and other packages.