Laravel dingo / api定制变压器

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?

Your PostTransformer isn't a Transformer. What you specified there is an TransformerLayer (https://github.com/dingo/api/wiki/Transformers#custom-transformation-layer).

However a Transformer in Dingo looks like this:

<?php

use League\Fractal\TransformerAbstract;

class PostTransformer extends TransformerAbstract
{
    public function transform(Post $post) {
        return [
            'id' => $post->id
            // ...
        ];
    }
}