wendelladriel / laravel-validated-dto
Data Transfer Objects with validation for Laravel applications
Package info
github.com/WendellAdriel/laravel-validated-dto
pkg:composer/wendelladriel/laravel-validated-dto
Requires
- php: ^8.2
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- illuminate/validation: ^11.0|^12.0|^13.0
Requires (Dev)
- laravel/pint: ^1.27
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^2.0|^3.0|^4.0
- pestphp/pest-plugin-faker: ^2.0|^3.0|^4.0
- spatie/typescript-transformer: ^2.5
- dev-main
- v4.7.0
- v4.6.0
- v4.5.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.0
- v4.0.0
- 3.x-dev
- v3.10.3
- v3.10.2
- v3.10.1
- v3.10.0
- v3.9.0
- v3.8.1
- v3.8.0
- v3.7.1
- v3.7.0
- v3.6.1
- v3.6.0
- v3.5.2
- v3.5.1
- v3.5.0
- v3.4.0
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.1
- v3.0.0
- v2.11.1
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- dev-feat/vitepress-docs
This package is auto-updated.
Last update: 2026-05-26 16:15:17 UTC
README
Validated DTO for Laravel
Data Transfer Objects with validation for Laravel applicationsInstallation
You can install the package via composer:
composer require wendelladriel/laravel-validated-dto
You can publish the config file with:
php artisan vendor:publish --tag="validated-dto"
Usage
Create a DTO by extending ValidatedDTO, declaring typed properties, and defining the validation rules for incoming data:
use Illuminate\Validation\Rules\Password; use WendellAdriel\ValidatedDTO\Casting\BooleanCast; use WendellAdriel\ValidatedDTO\Casting\StringCast; use WendellAdriel\ValidatedDTO\ValidatedDTO; final class UserDTO extends ValidatedDTO { public string $name; public string $email; public string $password; public bool $active; protected function rules(): array { return [ 'name' => ['required', 'string'], 'email' => ['required', 'email'], 'password' => ['required', Password::min(8)], 'active' => ['sometimes', 'boolean'], ]; } protected function defaults(): array { return [ 'active' => true, ]; } protected function casts(): array { return [ 'name' => new StringCast(), 'email' => new StringCast(), 'password' => new StringCast(), 'active' => new BooleanCast(), ]; } }
Create an instance from an array, request, JSON string, Eloquent model, or artisan command:
$dto = UserDTO::fromArray([ 'name' => 'John Doe', 'email' => 'john.doe@example.com', 'password' => 's3CreT!@1a2B', ]); $dto->name; // John Doe $dto->toArray();
You can also inject a DTO into a controller action and let the service container resolve it from the current request:
use Illuminate\Http\JsonResponse; final class StoreUserController { public function __invoke(UserDTO $dto): JsonResponse { return response()->json($dto->toArray()); } }
Access the full documentation here.
Changelog
Please see the changelog for more information on what has changed recently.
Contributing
Thank you for considering contributing to Validated DTO for Laravel! You can read the contribution guide here.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
Validated DTO for Laravel is open-sourced software licensed under the MIT license.