I've got the API working using the standard process, but I want to remove the data
namespace from the JSON output. I see I need to implement ArraySerializer, I have been through the Fractal docs, but I can't work out where I need to added it in Laravel 5.2
I found this answer but I'm just getting the same output at the line of code I commented out:
class TrackController extends ApiController
{
public function index()
{
$tracks = Track::all();
//return $this->respondWithCollection($tracks, new TrackTransformer);
// Same response as the commented out line above
$response = new \League\Fractal\Resource\Collection($tracks, new TrackTransformer);
$manager = new \League\Fractal\Manager();
$manager->setSerializer(new \League\Fractal\Serializer\ArraySerializer());
return response()->json($manager->createData($response)->toArray());
}
public function show($id)
{
$track = Track::find($id);
return $this->respondWithItem($track, new TrackTransformer);
}
}
Also, I'm implementing this on a specific controller, even if I got this working, where do I add the code/class so I can get ArraySerializer output for all my controllers?
I've posted this on Github if that helps.