wendelladriel/laravel-validated-dto
Create Data Transfer Objects that validate input on instantiation. Define rules once and reuse them across controllers, services, jobs, and CLI commands—reducing duplication and keeping validation decoupled from HTTP requests. Compatible with Laravel 11–13.
Illuminate\Validation\Rules) while abstracting it into reusable DTOs. This reduces redundancy in validation logic across HTTP requests, CLI commands, queues, and other layers.FormRequest classes for non-HTTP use cases (e.g., console commands, jobs, or background processes).#[Cast], #[Lazy]) to enforce type constraints at compile time, improving IDE support and reducing runtime errors.SkipOnTransform, Provide, Receive) and traits, allowing teams to extend functionality for domain-specific needs.SimpleDTO or ValidatedDTO and annotating properties with validation rules (e.g., #[Rule('required|string|max:255')]). The package provides Artisan commands (make:dto) to scaffold DTOs.Validator facade).#[Cast('date')]).Arrayable, Jsonable, and JsonSerializable, ensuring compatibility with Laravel’s response system (e.g., Resource classes).FormRequest validation may need time to adapt to DTO-centric validation.#[Lazy] or #[Provide] introduce indirection that could confuse developers unfamiliar with the pattern.FormRequest classes would need to be refactored into DTOs, requiring careful planning to avoid breaking changes.FormRequest-centric validation?#[Lazy]) introduce unexpected performance overhead in high-throughput systems?Validator, FormRequest, and custom validation rules.FormRequest, manual validation in controllers).make:dto to scaffold DTOs and migrate validation rules incrementally.FormRequest validation with DTOs in new features.FormRequest classes to use DTOs for validation.new UserCreateDTO($data)).FormRequest validation in favor of DTOs.deprecated() method or attribute-based deprecation warnings.FormRequest classes during migration.transformModelToArray, buildDataForExport).spatie/laravel-permission) or casting (e.g., nesbot/carbon).UserCreateDTO, OrderUpdateDTO).FormRequest validation rules with DTO attributes.UserResourceDTO) to standardize serialization.FormRequest validation and migrate to DTOs.max:255 → max:512) requires updating only the DTO.#[Lazy]) for onboarding."The email field in UserCreateDTO failed validation").#[Rule('...')]), reducing support tickets for syntax errors.#[Lazy]) defers validation until needed, which can improve performance for rarely used DTOs.#[Cacheable]) for high-frequency operations.#[Receive] (e.g., eager-loading relationships).ValidationException, which can be caught and converted to HTTP responses (e.g., 422 Unprocessable Entity) or CLI errors.#[Cast('json')]) may fail if input data is malformed.#[Rule] and #[Cast]) may lead to unexpected behavior.FormRequest and DTO validation) could lead to inconsistent error handling.DTO::fromArray()->validate()).How can I help you explore Laravel packages today?