Customizing The Pagination Information doesn't work for Resource::collection()
Hello, I am trying to customize pagination information for a resource collection. According to the 10.x docs
If you would like to customize the information included in the links or meta keys of the pagination response, you may define a paginationInformation method on the resource
I am returning my resource collection like so return CampaignIndexResource::collection($results->paginate());
Am I missing something? Does it only work for dedicated Collections?
use Illuminate\Http\Resources\Json\JsonResource;
class CampaignIndexResource extends JsonResource
{
public function paginationInformation($request, $paginated, $default)
{
$default['meta']['custom'] = 'https://example.com';
return $default;
}
public function toArray(Request $request)
{
return ['id' => '123'];
}
}
And the controller
public function index(Request $request) {
$results = Campaign::with('team');
return CampaignIndexResource::collection($results->paginate());
}
@BrMk Never done and never tested, but you should try to create a collection and define the custom pagination informations inside the collection instead of inside the resource.
class CampaignIndexCollection extends ResourceCollection
{
public function toArray($request)
{
return parent::toArray($request);
}
public function paginationInformation($request, $paginated, $default)
{
$default['meta']['custom'] = 'https://example.com';
return $default;
}
}