Laravel transformer vs resource
Asked Answered
H

2

18

I am little bit confused about the difference between Laravel eloquent resource and transformers. When i should use resource and when i should use transformers. Did some research on it from laravel documentation and medium article but its look like same purpose.

May be i have wrong concept about that. Any knowledge share from anyone will be appreciate.

Herby answered 18/9, 2018 at 4:1 Comment(3)
it looks like Transformer is a third-party package,in the other hand, Resources is officialAikens
can you share with us some hints? what are you actually getting confuse?.Blastogenesis
please visit those links i mentionedHerby
H
30

Laravel Eloquent API Resource was released on Laravel 5.5.

Before this feature exists officially, there was a package from spatie called spatie/laravel-fractal that's a wrap for league/fractal.

Both packages archives the same objective with different approach.

I prefer using the Eloquent API Resource since it's embedded on Laravel, so I reduce one (direct) dependency.

Note: The medium article uses the Fractal package, but this article is very superficial, you can find more detailed instructions on spatie/laravel-fractal, it you decide to use it.

Harumscarum answered 26/10, 2018 at 13:20 Comment(1)
awesome. thanks for your answer. i was looking for that.Herby
E
-6

Found this on a google search below your post:

You build out each "transformer" (which would be the equivalent of a "resource"), with the ability to include or not include whichever relationships you want solely based off the of request URL.

Eglanteen answered 26/10, 2018 at 13:13 Comment(1)
That's not the OP question, he asked the difference between using Laravel API Resource and Fractal Transformers.Harumscarum

© 2022 - 2024 — McMap. All rights reserved.