Validating a nested collection of data objects
When validating a data object like this:AlbumData would look like this:
NestedRules class is a Laravel validation rule that will validate each item within the collection for the rules defined on the data class for that collection.
Nullable and Optional nested data
If we make the nested data object nullable, the validation rules will change depending on the payload provided:null, the validation rules will be:
Optional nested data
The same happens when a property is made optional:We’ve written a blog post on the reasoning behind these variable validation rules based upon payload. And they are also the reason why calling
getValidationRules on a data object always requires a payload to be provided.