yajra/laravel-datatables-fractal
Fractal transformer plugin for yajra/laravel-datatables. Use League\Fractal to shape server-side DataTables JSON responses. Supports Laravel 12 / PHP 8.2+, with optional service provider and vendor:publish config/assets.
User::with('orders.items')) without manual JSON assembly.UserTransformer) across features, reducing duplication.composer require yajra/laravel-datatables-fractal:^12.0 + optional service provider registration.Yajra\DataTables\DataTables with Fractal transformers (e.g., ->transform(Fractal::collection($query->get(), new UserTransformer()))).| Risk | Mitigation | Severity |
|---|---|---|
| Fractal Learning Curve | Leverage existing Fractal docs and Laravel DataTables experience. | Low |
| Performance Overhead | Use Fractal::collection($query->cursor()) for large datasets. |
Medium |
| Breaking Changes | Package aligns with Laravel minor versions (e.g., v12.x for Laravel 12.x). | Low |
| Frontend Incompatibility | Ensure client-side DataTables config matches server response schema. | Medium |
| Transformer Complexity | Start with simple transformers; refactor as needed. | Low |
composer require yajra/laravel-datatables-fractal:^12.0.php artisan vendor:publish --tag=datatables-fractal.UserTransformer, OrderTransformer).return DataTables::of(User::query())
->transform(function ($query) {
return Fractal::collection($query->get(), new UserTransformer());
});
Yajra\DataTables\DataTables for non-Eloquent data.data, recordsTotal, etc.response.data).include parameter (e.g., ?include=orders).data but gets items (configurable via Fractal).with() or load()).Debug::debug() for transformer output.->toJson() for raw response inspection.Fractal::collection($query->cursor()) for large datasets.->include('orders')).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Transformer Error | Broken API response | Use try-catch in transformers; log errors to Sentry. |
| Schema Drift | Frontend breaks on field changes | Version transformers (e.g., UserTransformerV1, V2). |
| Performance Degradation | Slow responses for large datasets | Implement cursor loading; profile with tntsearch/laravel-query-cache. |
| Fractal Package Issues | Dependency conflicts | Pin versions in composer.json; monitor GitHub issues. |
| Frontend Incompatibility | DataTables.js fails to render | Validate response schema with Postman/Insomnia before frontend integration. |
How can I help you explore Laravel packages today?