SongData object from these values by using the SongData class we saw in an earlier chapter:
Controller Injection
You can now inject theSongData class in your controller. It will already be filled with the values found in the request:
As an added benefit, these values will be validated before the data object is created. If the validation fails, a
ValidationException will be thrown which will look like you’ve written the validation rules yourself.Manual Creation from Request
The package will also automatically validate all requests when passed to the from method:We have a complete section within these docs dedicated to validation, you can find it here.
Getting Data Object from Anywhere
You can resolve a data object from the container:Validating a Collection of Data Objects
Let’s say we want to create a data object like this from a request:SongData has its own validation rules, the package will automatically apply them when resolving validation rules for this object.
In this case the validation rules for AlbumData would look like this: