I've searched here and in fractal docs and i found that i need to replace DataArraySerializer with ArraySerializer
$manager->setSerializer(new ArraySerializer());
but i have no idea where to put this in Laravel. I tried putting
$fractal = app(Manager::class);
$fractal->setSerializer(new DataArraySerializer);
in controller's construct but it doesn't change anything. Any ideas?
I just had this question myself and wound up finding an answer that worked: https://joshhornby.co.uk/blog/laravel-dingo-json-api-spec
You'll basically create a new ServiceProvider file, within your App/Providers folder (or wherever you'd normally prefer), and then include this within your config/app.php file's 'providers' array (the same way they include the AppServiceProvider::class etc).
That's all you have to do to globally change the default serializer used. Of course, you'll have to make modifications to the code provided on the above URL, as you want to use ArraySerializer instead.
In a service provider...
$this->app['Dingo\Api\Transformer\Factory']->setAdapter(function ($app) {
$manager = new League\Fractal\Manager;
$manager->setSerializer(new ArraySerializer);
return new Dingo\Api\Transformer\Adapter\Fractal($manager, 'include', ',');
});
It didn't work for me, when I user includeDefaults inside the transformer, It appends data key. :-(
Most helpful comment
In a service provider...