- What does toneflix/laravel-resource-modifier do?
- It is a lightweight extension for Laravel API resources that lets you attach reusable modifiers to any JsonResource and reshape the final JSON payload at runtime. You can conditionally add, rename, or remove fields without rewriting or duplicating resource classes. It works alongside existing resource methods such as when() and helps keep controllers concise.
- How do I install toneflix/laravel-resource-modifier?
- Install it with Composer using composer require toneflix/laravel-resource-modifier. The 2.0.0 release requires PHP 8.3 or 8.4 and Laravel 12 or 13, so confirm your application meets those platform requirements first. After installation, define your modifiers and attach them to your JsonResource classes; setup is minimal.
- Which Laravel and PHP versions does toneflix/laravel-resource-modifier support?
- Version 2.0.0 requires PHP ^8.3 or ^8.4 and Illuminate ^12.0 or ^13.0, which means Laravel 12 and Laravel 13. It drops support for Laravel 10 and 11 as well as PHP 8.1 and 8.2. If your application is not already on Laravel 12 or newer, you cannot adopt this release and must stay on the 1.x line.
- How do I attach a modifier to a Laravel JsonResource?
- You define a reusable modifier and attach it to any JsonResource before the response is returned. Because modifiers are composable units, the same transformation can be reused across multiple resource classes and controllers. The package is designed as a framework-native API with minimal setup, so it slots into your existing resource usage rather than replacing it.
- Can I chain multiple modifiers on a single resource?
- Yes. The package supports chaining multiple modifiers, and they are applied in a predictable order. That lets you compose small, single-purpose transformations instead of building one large resource class. Keep ordering in mind when one modifier removes or renames a field that another modifier expects.
- Does it work with when() and my existing resource methods?
- Yes, the package is designed to work alongside when() and existing resource methods. It extends Laravel's API resource behaviour rather than replacing it, so conditional fields you already define continue to work. You should still test the interaction and ordering with conditional fields, since modifiers operate on the resource output.
- How do I migrate from toneflix-code/laravel-resource-modifier 1.x to 2.0?
- The 2.0.0 release re-homes the package under toneflix/laravel-resource-modifier and renames the namespace, so migration is primarily a Composer swap plus a global namespace replacement in application code and published config. Remove the old package, require the new one, then update every FQCN reference, including strings in config, container bindings, cached fragments, and queued payloads. Do it in a single PR and grep for the old vendor and namespace to avoid a half-migrated repository. Also check whether the old Packagist name is marked abandoned so tooling can route you to the replacement.
- Will the old toneflix-code package be marked abandoned on Packagist?
- The context does not confirm whether the old package name will be flagged abandoned with the new name as the suggested replacement. If it is not flagged, dependency scanners and upgrade tooling will keep treating it as a live dependency and will not surface the migration. Ask the maintainer directly and check the Packagist page for an abandoned flag before planning your rollout.
- Is toneflix/laravel-resource-modifier a good alternative to Fractal or custom DTO transformers?
- It is a good fit if your application already standardizes on Laravel API Resources and you want runtime field shaping without duplicating resource classes. It is a poor fit if you use a dedicated transformer layer such as Fractal or hand-rolled DTOs, because adopting it would introduce a second, competing transformation idiom. Choose one transformation layer per codebase rather than mixing them.
- Is toneflix/laravel-resource-modifier safe to use in production?
- The package sits on the serialization path between Eloquent models and JSON responses, so its blast radius is narrow and it does not touch persistence, routing, auth, or queues. However, 2.0.0 is a rename and platform-floor release rather than a feature release, and Laravel 13 is still new, so production exposure to the retargeted major is unproven. Test field ordering, nested resources, and pagination envelopes in your own suite before rolling it out. Also review the maintainer bus factor and release cadence.