There are a few ways to define default values for a data object. Since a data object is just a regular PHP class, you can use the constructor to set default values:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spatie/laravel-data/llms.txt
Use this file to discover all available pages before exploring further.
Complex Default Values
But what if you want to set a default value for a more complex type like aCarbonImmutable object? You can use the constructor to do this:
Default Values with Validation
Even validation will work:Requirements for Complex Defaults
There are a few conditions for this approach:Use a sole property
You must always use a sole property, a property within the constructor definition won’t work
Add Optional type (recommended)
The optional type is technically not required, but it’s a good idea to use it otherwise the validation won’t work