Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel5 Fractal

Laravel5 Fractal Laravel Package

cyvelnet/laravel5-fractal

Laravel 5 Fractal offers a simple Laravel-friendly wrapper around League Fractal for transforming Eloquent models and collections into clean API responses, with reusable transformers, includes, serializers, and pagination support.

View on GitHub
Deep Wiki
Context7

A simple fractal service provider and transformer generator for laravel >=5

Frequently asked questions about Laravel5 Fractal
How do I install cyvelnet/laravel5-fractal in a Laravel application?
Install it with composer require cyvelnet/laravel5-fractal. On Laravel 5.5 and later the service provider is registered through package auto-discovery, so no manual provider entry is needed. You can optionally publish the config file if you want to customize serializer or include settings. There are no migrations, infrastructure changes, or runtime service dependencies involved.
Which Laravel and PHP versions does laravel5-fractal support?
The package name says Laravel 5, but you should not assume that reflects current support. The last release metadata is dated 2024-03-13, so verify the composer.json constraints for both this package and league/fractal against your target Laravel and PHP versions. Pin exact versions and run your test suite across the version matrix in CI before adopting it. It is best suited to Laravel 5.x through 8.x era applications or teams already committed to Fractal.
What does laravel5-fractal actually add on top of league/fractal?
It is a thin Laravel convenience layer, not a framework. It provides a service provider that binds League\Fractal\Manager into the container, plus an Artisan make:transformer generator and likely a config file or facade. All the real transformation logic, serializers, includes, and pagination primitives live in league/fractal itself. Its value is developer ergonomics, and it is small enough to be replaced with roughly 50 lines of internal code if needed.
How do I generate a transformer with this package?
Run php artisan make:transformer UserTransformer after installing the package. The generator scaffolds a transformer class where you implement the transform method and return the array shape you want in your API response. You then wire that transformer into your controller through the container-bound Fractal manager. Commit a golden JSON snapshot of the output so later refactors can be verified for parity.
Should I use laravel5-fractal or Laravel's native API Resources?
For greenfield Laravel 9, 10, or 11 applications, native API Resources are the lower-risk default because they ship with the framework and need no extra dependency. Choose Fractal through this package only if you specifically need capabilities like the JsonApi serializer, includes, sparse fieldsets, or its pagination primitives. Do not mix both approaches in one codebase, because inconsistent output shapes and conventions become a maintenance problem.
Does laravel5-fractal support includes, sparse fieldsets, and pagination?
Yes, those features come from league/fractal rather than the wrapper itself. You get includes, serializer selection such as Array or JsonApi, sparse fieldsets, and Fractal's pagination primitives through the bound manager. The main functional risk is silent output-shape differences versus native resources, especially around serializers, include handling, and null values. Verify response payloads with snapshot tests before rolling out broadly.
Is cyvelnet/laravel5-fractal still actively maintained?
It is a small, single-maintainer package with around 79 stars, so the bus factor is low and there is no vendor SLA. Because the package is thin, fork-and-own is a cheap mitigation if upstream goes quiet. Budget a light recurring review cadence to track league/fractal releases, security advisories, and PHP and Laravel end-of-life dates. Document the container binding and generator workflow internally so knowledge does not sit with one engineer.
What are the alternatives to laravel5-fractal?
If you need Fractal specifically, spatie/laravel-fractal offers a similar surface with a more active maintenance record. If you do not need Fractal-only features, Laravel's native JsonResource is the lowest-risk option for new projects. You can also hand-wire League\Fractal\Manager yourself in a service provider, which is a reasonable choice given how little this wrapper adds.
How should I test transformer output to catch regressions?
Use golden-output JSON snapshot tests for each endpoint or transformer. This is especially important when migrating from hand-wired Fractal, where you should confirm byte-for-byte output parity before switching. Eager-load relations in your tests as well so N+1 queries and missing includes surface early. Run the full suite against your supported Laravel and PHP version matrix in CI.
Can I migrate from laravel5-fractal to native API Resources later?
Yes, and the migration is straightforward because the package is only a wrapper. Map each transformer to a JsonResource, translate includes to whenLoaded or whenIncluded, and replace Fractal serializers with resource wrapping. Migrate endpoint by endpoint behind a feature flag and compare snapshot output at each step. Reassess build-versus-fork after a one-endpoint spike rather than committing to broad adoption up front.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager