php - How to return array instead of collection using Fractal Transformers in Laravel

one text

Solution:

I found a workaround for this. We can use the flatten() method of Laravel collections and it will make the returned array single dimensional. So the code will be as follows :

$data = fractal($release, new ReleaseTransformer())->toArray();

$dataAsArray = collecet($data)->flatten()->all();

PS: I am not sure it is a correct to use transformers for the scenario I have mentioned, but just putting the answer if someone needs it.

Source