There are two ways to tell Lumen which transformer class has to be used. For that, we need to create a transformer class. Let's first make a transformer for our Post object and name it PostTransformer. First, create a directory named app/Transformers and in that directory, create a class PostTransformer with the following content:
<?phpnamespace App\Transformers;use League\Fractal;class PostTransformer extends Fractal\TransformerAbstract{ public function transform(\App\Post $post) { return $post->toArray(); }}
You can do whatever you want to do with the Post response in the transform() method. Note that we are not optionally overriding the transform() method here, but we are providing an implementation of transform() ...