This is what I’ve been doing for a while now:
<?php
namespace AppProviders;
use IlluminateSupportServiceProvider;
use IlluminateHttpResourcesJsonJsonResource;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
JsonResource::macro('paginationInformation', function ($request, $paginated, $default) {
array_shift($default['meta']['links']);
array_pop($default['meta']['links']);
return $default;
});
}
}
I was wondering if there’s a best practice to do it – or a Laravel provided way to do it, like a built-in “removePrevNextLinks” or something.
Example response I get:
And basically, this is the goal:
So I still want to keep the links – except the “Previous” and “Next” ones.
But without messing with the service provider, using laravel-provided methods instead of customizations like the above.
I checked out other stack posts, but most of them removed the meta links completely, or other solutions that does not provide the desired response.