Laravel Validated DTO stops data type bugs before they reach production
The Problem with Request Validation
Standard Laravel form requests validate incoming HTTP data, but they leave payload values as loose strings or integers. When you need to cast boolean flags, instantiate Carbon instances, or resolve Enums, you typically write manual transformation logic in your controllers. If you reuse that request data across console commands, queued jobs, or background services, you must replicate those transformations everywhere. This fractured approach scatters your data schemas and exposes your code to runtime type errors.
Combining Validation and DTOs
Laravel Validated DTO, developed by Wendell Adriel, resolves this issue. By merging validation rules with strict data transfer objects, it creates a single, reusable class that acts as the absolute source of truth for your data structures.
use WendellAdriel\ValidatedDTO\ValidatedDTO;

class CreateEventDTO extends ValidatedDTO { public string $title; public bool $is_public; public CarbonImmutable $starts_at; public EventFormat $format; public VenueDTO $venue;
protected function rules(): array
{
return [
'title' => ['required', 'string'],
'is_public' => ['boolean'],
'starts_at' => ['required', 'date'],
'format' => ['required', 'string'],
];
}
protected function casts(): array
{
return [
'is_public' => 'boolean',
'starts_at' => 'datetime',
'format' => EventFormat::class,
'venue' => VenueDTO::class,
];
}
}
## Structural Type Safety and Nested Objects
This package handles nested objects natively. You can cast nested structures directly into child DTOs, enforcing type safety down through deep array payloads (e.g., nesting a `VenueDTO` inside your parent `EventDTO`).
```php
protected function casts(): array
{
return [
'venue' => VenueDTO::class,
];
}
Resolving Key Mapping Inconsistencies
API client payloads often mismatch database schemas. The package addresses this with a dedicated mapping method, allowing you to transform request parameters seamlessly into your internal database column names.
protected function mapData(): array
{
return [
'promo_code' => 'promotion_code',
];
}
- Laravel Validated DTO
- 50%· products
- Wendell Adriel
- 50%· people

Laravel Validated DTO Package: Why/When You Would Need It?
WatchLaravel Daily // 11:21