Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Laravel
  3. Laravel Fractal

Laravel Fractal

MITPHP6.4.0

A Laravel wrapper for Fractal that simplifies API data transformation with an expressive syntax.

Visit WebsiteGitHubGitHub
1.9k stars185 forks0 contributors

What is Laravel Fractal?

Spatie's Laravel Fractal is a wrapper package that integrates the Fractal transformation library into Laravel and Lumen applications. It simplifies the process of transforming data, such as Eloquent models or arrays, into structured JSON outputs suitable for APIs. The package provides an expressive syntax and helper methods to reduce boilerplate code when building API responses.

Target Audience

Laravel and Lumen developers building RESTful or JSON APIs who need to transform complex data structures into consistent, well-formatted JSON responses. It's particularly useful for backend developers working on API-driven applications.

Value Proposition

Developers choose this package because it offers a more intuitive and Laravel-idiomatic way to use Fractal, with features like fluent chaining, direct Eloquent model transformation, and built-in response helpers. It reduces the complexity of raw Fractal usage while maintaining full flexibility.

Overview

An easy to use Fractal wrapper built for Laravel and Lumen applications

Use Cases

Best For

  • Transforming Eloquent query results into API-ready JSON structures
  • Building consistent JSON:API or RESTful endpoints in Laravel applications
  • Simplifying complex data transformations with an expressive, chainable syntax
  • Handling nested includes and excludes dynamically from request parameters
  • Reducing boilerplate code when formatting API responses
  • Integrating Fractal's transformation capabilities seamlessly into Laravel projects

Not Ideal For

  • Projects not using the Laravel framework, as the package is tightly integrated and offers no benefits outside of it.
  • Simple APIs with straightforward data structures that don't require complex transformations, making the overhead unnecessary.
  • Teams already leveraging Laravel's native API resources or other data transformation packages, as it adds redundant complexity.
  • Applications with strict dependency management policies that avoid external packages for core functionality.

Pros & Cons

Pros

Expressive Fluent Syntax

Offers a chainable interface that simplifies data transformation compared to raw Fractal usage, as demonstrated in the README's code examples with methods like `includeCharacters()`.

Seamless Laravel Integration

Directly works with Eloquent models and collections, allowing easy transformation of database results without extra steps, such as `Users::all()->transformWith(new UserTransformer())`.

Built-in Response Helpers

Includes a `respond()` method to return JSON responses with status codes and headers, streamlining API endpoint creation and reducing boilerplate code.

Auto-Configuration for Includes

Configurable handling of include and exclude parameters from request data via the config file, reducing manual parsing boilerplate for dynamic API responses.

Cons

External Dependency Overhead

Relies on the Fractal library, adding another layer that must be maintained and understood, which can complicate debugging and increase project complexity.

Breaking Changes History

The README documents several breaking changes between versions (e.g., v2 to v3 dropping Lumen support and config file renames), indicating potential upgrade challenges and maintenance headaches.

Limited Framework Support

Primarily designed for Laravel, with Lumen support dropped in later versions, making it unsuitable for other PHP frameworks or non-Laravel projects.

Frequently Asked Questions

Quick Stats

Stars1,910
Forks185
Contributors0
Open Issues0
Last commit6 days ago
CreatedSince 2015

Tags

#eloquent#json-api#lumen#api#laravel#rest-api#fractal#backend#php#data-transformation

Built With

L
Lumen
C
Composer
P
PHP
L
Laravel

Links & Resources

Website

Included in

Laravel13.0k
Auto-fetched 23 hours ago

Related Projects

LiveWireLiveWire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Stars23,529
Forks1,737
Last commit3 days ago
Debug BarDebug Bar

Debugbar for Laravel (Integrates PHP Debug Bar)

Stars19,230
Forks1,606
Last commit3 days ago
IDE HelperIDE Helper

IDE Helper for Laravel

Stars14,925
Forks1,190
Last commit1 month ago
Intervention ImageIntervention Image

PHP Image Processing

Stars14,344
Forks1,490
Last commit1 day ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub