Laravel JSON API Paginate

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.

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.
1
use App\Models\Job;
2
3
class JobsController extends Controller
4
{
5
public function index()
6
{
7
return Job::query()->jsonPaginate();
8
}
9
}

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:

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.
1
<?php
2
3
return [
4
// ..... other config options .....
5
6
/*
7
* The key of the page[x] query string parameter for page number.
8
*/
9
'number_parameter' => 'number',
10
'number_parameter' => 'num',
11
12
/*
13
* The key of the page[x] query string parameter for page size.
14
*/
15
'size_parameter' => 'size',
16
'size_parameter' => 'amount',
17
18
// ..... other config options .....
19
];

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.

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
1
<?php
2
3
return [
4
// ..... other config options .....
5
6
/*
7
* The key of the page[x] query string parameter for cursor.
8
*/
9
'cursor_parameter' => 'cursor',
10
11
/*
12
* If you want to cursor pagination, set this to true.
13
* This would override use_simple_pagination.
14
*/
15
'use_cursor_pagination' => true,
16
17
// ..... other config options .....
18
];
Scramble PRO
Comprehensive API documentation generation for Spatie’s Laravel Data, Laravel Query Builder, and other packages.