You can just use paginate.
eg
/**
* Display a listing of the resource.
*
* @return AnonymousResourceCollection
*/
public function __invoke(): AnonymousResourceCollection
{
return ActivityTypeResource::collection(ActivityType::paginate());
}
adds the following to your json response:
"links": {
"first": "https://your-api.com/api/v1/activity-types?page=1",
"last": "https://your-api.com/api/v1/activity-types?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"links": [
{
"url": null,
"label": "« Previous",
"active": false
},
{
"url": "https://your-api.com/api/v1/activity-types?page=1",
"label": "1",
"active": true
},
{
"url": null,
"label": "Next »",
"active": false
}
],
"path": "https://your-api.com/api/v1/activity-types",
"per_page": 15,
"to": 13,
"total": 13
}