I am trying to implement a custom transformer using dingo api (https://github.com/dingo/api/wiki/Transformers#custom-transformation-layer) for my Post model and I am getting this exception:
Missing argument 2 for PostTransformer::transform(), called in /home/.../vendor/league/fractal/src/Scope.php on line 298 and defined
My controller:
$post = Post::findOrFail(2);
return $this->item($post, new PostTransformer);
My PostTransformer class:
<?php
use Illuminate\Http\Request;
use Dingo\Api\Transformer\Binding;
use Dingo\Api\Transformer\TransformerInterface;
class PostTransformer implements TransformerInterface
{
public function transform($response, $transformer, Binding $binding, Request $request)
{
// Make a call to your transformation layer to transformer the given response.
return [
'kkk' => 'val'
];
}
}
What is wrong?