Download the PHP package php-collective/laravel-dto without Composer
On this page you can find all versions of the php package php-collective/laravel-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download php-collective/laravel-dto
More information about php-collective/laravel-dto
Files in php-collective/laravel-dto
Package laravel-dto
Short Description Laravel integration for php-collective/dto
License MIT
Informations about the package laravel-dto
Laravel DTO
Laravel integration for php-collective/dto.
Installation
The service provider will be auto-discovered.
Configuration
Publish the config file:
This creates config/dto.php with the following options:
Usage
1. Initialize DTO configuration
This creates a config/dto.php file with a sample DTO definition (PHP format is the default).
You can also use --format=xml or --format=yaml.
The generated config looks like:
2. Generate DTOs
Options:
--dry-run- Preview changes without writing files-v- Verbose output
3. Generate TypeScript interfaces
4. Generate JSON Schema
5. Use your DTOs
Eloquent Integration
Attribute Casting
Or opt into automatic casts:
Model to DTO
You can also extend the base model:
Mapping Helpers
API Resources
Request Integration
DtoFormRequest
DtoResolver
Register once (e.g. in AppServiceProvider::boot()):
Then inject DTOs directly:
Collections
The service provider automatically registers Laravel's Illuminate\Support\Collection for DTO collection fields. Define collection fields with the [] suffix:
After generating, collection fields use Laravel's Collection class with all its methods (filter, map, pluck, etc.).
Validation Bridge
Convert DTO validation rules to Laravel validation arrays with DtoValidationRules::fromDto(). Integrates directly with Form Requests. See Usage Guide for details.
Supported Config Formats
The package supports multiple config file formats:
dto.php- PHP format (default)dto.xml- XML formatdto.yml/dto.yaml- YAML formatdto/subdirectory with multiple files
License
MIT