Installation via Composer
You can install Laravel Data using Composer:Laravel’s package auto-discovery will automatically register the service provider, so no manual registration is needed.
Publishing the configuration
The package works out of the box with sensible defaults. However, you can optionally publish the configuration file to customize behavior:config/data.php file in your application.
Configuration overview
The published configuration file allows you to customize:Date handling
Date handling
Configure date formats and timezones for date transformations:
Global transformers
Global transformers
Define transformers that convert complex types to simple types:
Global casts
Global casts
Define casts that convert simple types to complex types:
Rule inferrers
Rule inferrers
Configure how validation rules are automatically inferred from property types:
Structure caching
Structure caching
Enable caching for improved performance in production:
Validation strategy
Validation strategy
Control when data objects are validated:Options:
OnlyRequests: Validate only when creating from requests (default)Always: Validate on every creationDisabled: Never validate automatically
Make command defaults
Make command defaults
Configure the
make:data Artisan command:Debugging with var dumper
Debugging with var dumper
Controls how data objects appear when using
dump() or dd():'enabled'- Always use the custom caster (shows data properties clearly)'disabled'- Never use the custom caster (standard object dump)'development'(default) - Use custom caster only in non-production environments
Creating data classes
You can quickly generate a data class using the Artisan command:app/Data/PostData.php:
Performance optimization
For production environments, ensure structure caching is enabled inconfig/data.php:
Next steps
Quickstart
Build your first data object
Requirements
Check system requirements