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.
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.