Weave Code
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
Laravel Datatables Fractal

Laravel Datatables Fractal Laravel Package

yajra/laravel-datatables-fractal

Laravel DataTables plugin that transforms server-side JSON responses using League Fractal. Adds Fractal integration to yajra/laravel-datatables for cleaner, consistent API output. Supports PHP 8.2+ and Laravel 12.x.

View on GitHub
Deep Wiki
Context7

yajra/laravel-datatables-fractal is an official plugin for Laravel DataTables that transforms server-side DataTables responses using League Fractal. It helps you standardize and serialize your table payloads with a clean transformer layer, keeping controllers thin and responses consistent.

Built for modern Laravel apps (PHP 8.2+, Laravel 12.x), it integrates seamlessly with the Yajra DataTables ecosystem and can be configured via optional publishing.

  • Fractal-powered transformers for DataTables responses
  • Works with Laravel DataTables server-side processing
  • Supports Laravel 8–13 via matching package versions
  • Optional service provider registration and config publishing
  • Simple install via Composer (composer require ...)
Frequently asked questions about Laravel Datatables Fractal
How do I install yajra/laravel-datatables-fractal in a Laravel 12 project?
Run `composer require yajra/laravel-datatables-fractal:^12.0` to install the package. Laravel 12+ auto-discovers the service provider, so no manual registration is needed unless you’re using an older version. Ensure you also have `yajra/laravel-datatables` installed as a dependency.
Can I use this package without yajra/laravel-datatables?
No, this package is a plugin for `yajra/laravel-datatables` and requires it to function. If you’re not already using DataTables for server-side processing, consider alternatives like Laravel’s built-in API Resources or Spatie’s Laravel Query Builder.
What’s the difference between this and Laravel’s built-in API Resources?
This package integrates Fractal transformers directly with DataTables’ server-side processing, enabling dynamic `include` and `fields` parameters for granular data control. API Resources lack this flexibility for DataTables-specific queries, making this ideal for admin dashboards or SPAs needing dynamic table responses.
How do I configure custom transformers for DataTables responses?
Publish the config with `php artisan vendor:publish --tag=datatables-fractal`, then define transformers in the `app/Transformers` directory. Use Fractal’s `ItemTransformer` or `CollectionTransformer` to shape your DataTables query results. Example: `return fractal($query->get(), new UserTransformer());` in your DataTables controller.
Does this package support Laravel 13?
Yes, the package supports Laravel 13 via the `^13.0` version tag. Check the [compatibility table](https://github.com/yajra/laravel-datatables-fractal#laravel-version-compatibility) for exact version mappings. Always update dependencies to avoid breaking changes.
How do I handle nested relationships with include/fields parameters?
Enable dynamic includes by adding `$this->app->make('datatables')->include('relationships')` to your DataTables query. Use Fractal’s `include` method in transformers to load nested data. Example: `?include=orders&fields[users]=id,name` fetches only specified fields for related models.
Will this package slow down my DataTables queries?
No, it inherits DataTables’ efficient server-side processing and Fractal’s lazy serialization. However, improperly configured `include` or `fields` parameters can cause over-fetching. Test with `DB::enableQueryLog()` to ensure no N+1 queries occur in production.
Can I use this with Laravel’s API Resources instead of Fractal?
No, this package is designed for Fractal transformers and won’t work with API Resources. If you prefer API Resources, consider using `yajra/laravel-datatables` alone or extending it with custom JSON serialization logic in your controllers.
How do I test DataTables responses with Fractal transformers?
Mock the DataTables query builder and Fractal’s `Manager` in your tests. Use `DataTables::of(Model::class)` to simulate server-side processing, then assert the transformed JSON structure. Example: `$response->assertJsonStructure(['data' => ['*' => ['id', 'name']]]).`
What’s the best way to migrate existing DataTables endpoints to use Fractal?
Start by wrapping your DataTables query in a Fractal transformer in the controller. Gradually refactor high-traffic endpoints first. Use `php artisan vendor:publish --tag=datatables-fractal` to customize default settings. Test each endpoint with tools like Postman to verify the new JSON structure.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport