- How do I install yorcreative/laravel-argonaut-dto in a Laravel app?
- Install it with Composer using composer require yorcreative/laravel-argonaut-dto. The package is lightweight and the README does not require publishing a config file or registering a service provider manually. After installing, extend ArgonautDTO in your own classes and declare the properties, casts, and validation rules you expect.
- Which PHP and Laravel versions does Laravel Argonaut DTO support?
- It supports PHP 8.2, 8.3, 8.4, and 8.5, and Laravel 10.x, 11.x, 12.x, and 13.x. Laravel 13 requires PHP 8.3 or higher. Recent releases also declare their illuminate/* dependencies explicitly, so it is worth checking that your pinned Laravel minor resolves cleanly with composer why-not before upgrading.
- How does nested casting work for arrays of DTOs?
- Argonaut supports deep nested transformation, so a DTO property typed as another DTO class is cast recursively when the source data is an array or object. Collections and arrays of items are converted into arrays of nested DTOs rather than left as raw arrays. This keeps a consistent data shape across service layer and API boundaries without manual mapping code.
- How is validation handled inside an Argonaut DTO?
- Validation is built on Laravel's own validator, so you write rules using the standard Laravel rule syntax you already know. Rules are declared on the DTO and applied when data is hydrated into it, which means invalid payloads are rejected before they reach your service layer. Validation errors therefore flow through Laravel's usual validation handling.
- How do I convert a DTO back to an array or JSON?
- Every DTO exposes toArray() and toJson() for clean serialization. Serialization is recursive, so nested DTOs are converted to nested arrays or JSON objects rather than leaking objects into your response. That makes DTOs convenient to return directly from controllers or API resources.
- Are Argonaut DTOs immutable, and can I use readonly properties?
- Yes, Argonaut DTOs are designed to be immutable and support readonly properties. Values are resolved at construction time, with explicit attribute prioritization determining which source value wins when data overlaps. After hydration the DTO should be treated as a fixed snapshot of the data.
- Can I hydrate a DTO from an Eloquent model or an existing object?
- DTOs can be built from arrays, objects, and collections, so an Eloquent model or a query result collection can be transformed directly. The package does not couple itself to Eloquent, so the usual pattern is to use an assembler or mapper class that turns a model into a DTO. That keeps your domain objects decoupled from the persistence layer.
- Is Laravel Argonaut DTO safe to use in production?
- It is a community-maintained package with a small contributor base, which is the main thing to weigh for critical systems. Recent releases cleared outstanding security advisories, declared their illuminate dependencies explicitly, and raised PHPStan analysis to level 8, which reduces compliance and type-safety concerns. Pin the version, keep a regression suite over your DTO validation and assembly paths, and review the changelog before each minor bump.
- What are the alternatives to Laravel Argonaut DTO?
- The most common comparison is spatie/laravel-data, which offers a broader feature set around DTOs, casts, and validation. Argonaut positions itself as lighter and more composable, focusing on nested casting, immutable DTOs, Laravel validation, and simple toArray/toJson serialization. Some teams also use plain readonly PHP classes when their mapping needs are simple.
- Does upgrading Laravel Argonaut DTO break existing DTOs?
- Recent minor releases such as v1.6.0 are non-breaking and limited to dependency metadata, advisory fixes, and tighter static analysis. The main upgrade risk is Composer resolution: explicitly declared illuminate/* constraints can surface a conflict that was previously satisfied implicitly. Treat a bump as a drop-in change behind your normal CI gate and run the full test suite.