Disable Property Name Mapping
We saw earlier that it is possible to map property names when creating a data object from an array. This can be disabled when using a factory:Changing the Validation Strategy
By default, the package will only validate Requests when creating a data object it is possible to change the validation strategy to always validate for each type:Disabling Magic Methods
A data object can be created using magic methods, this can be disabled when using a factory:Disabling Optional Values
When creating a data object that has optional properties, it is possible choose whether missing properties from the payload should be created asOptional. This can be helpful when you want to have a null value instead of an Optional object - for example, when creating the DTO from an Eloquent model with null values.
Adding Additional Global Casts
When creating a data object, it is possible to add additional casts to the data object:data.php config file, they will though run before the other global casts. You define them just like you would define them in the config file, the first parameter is the type of the property that should be cast and the second parameter is the cast class.
Using the Creation Context
Internally the package uses a creation context to create data objects. The factory allows you to use this context manually, but when using the from method it will be used automatically. It is possible to inject the creation context into a magical method by adding it as a parameter:You can read more about creation contexts here.