Laravel default paginate gave me the response with default format for pagination, but I want to remove links in the meta object at the page response
I used below code to fetch the page data:
public function index()
{
return response()->json(
new EntityCollection(Entity::paginate($pageSize))
);
}
It return the response in resource collection I called EntityCollection in my codes. But I want to remove links in the meta at the response.
EntityCollection looks like this:
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class EntityCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection,
];
}
}
When I use EntityCollection to fetch the list it returns below format response:
{
"data": [
// data
],
"links": {
"first": "*url?page_size=1&page=1",
"last": "*url?page_size=1&page=15",
"prev": null,
"next": "*url?page_size=1&page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 15,
"links": [
{
"url": null,
"label": "pagination.previous",
"active": false
},
{
"url": "*url?page_size=1&page=6",
"label": 6,
"active": false
}
],
"path": "*url",
"per_page": "1",
"to": 1,
"total": 15
}
}
Please give me the way to remove links in the meta or the best practice to customise the response of paginate in Laravel.