Closed manyeung closed 5 years ago
To be honest, I've never used the transformers in that way, I use the other methods you've mentioned.
I recommend not using the transformer factory, the whole routing aspect of Dingo needs a good re-write, so IMO it's not worth spending time looking at this.
If you want to have a look and submit a PR, I'll be happy to review it though :)
I've looked into it, basically User::paginate() will just return a LengthAwarePaginator instance, and Dingo will not know what to do with it - you need to use dingo's response functions (like in your example that works).
I am not sure what the problem is to be honest.
@specialtactics According to the wiki, it has mentioned below:
// When you register a transformer for a given class you'll be able to return the class (assuming it can be turned into an array) directly from your routes and it'll be run through the transformer automatically. This is great for simple APIs where you're using models as you can simply return the model from your route. //
Do you mean that the app('Dingo\Api\Transformer\Factory')->register('User', 'UserTransformer');
only works for Model but not for Eloquent\Collection and LengthAwarePaginator?
@manyeung Yes, maybe the paginator more so than collection - but I didn't test that distinction.
I am following the wiki to use the transformer but it does not work after update the framework from Laravel 5.4 to 5.5+.
$this->response->paginator()
,$this->response->item()
and$this->response->collection()
works fine butapp('Dingo\Api\Transformer\Factory')->register()
does not work.Actual Behaviour
Expected Behaviour
Steps to Reproduce
routes/api.php:
UserController.php:
UserTransformer.php: