required and string rule, these will be added automatically. The rules for the
above data object will look like this:
Referencing route parameters
Sometimes you need a value within your validation attribute which is a route parameter. Like the example below where the id should be unique ignoring the current id:Referencing the current authenticated user
If you need to reference the current authenticated user in your validation attributes, you can use theAuthenticatedUserReference:
Referencing container dependencies
If you need to reference a container dependency in your validation attributes, you can use theContainerReference:
Referencing other fields
It is possible to reference other fields in validation attributes:Rule attribute
One special attribute is theRule attribute. With it, you can write rules just like you would when creating a custom
Laravel request:
Creating your validation attribute
It is possible to create your own validation attribute by extending theCustomValidationAttribute class, this class
has a getRules method that returns the rules that should be applied to the property.
You can only use these rules as an attribute, not as a class rule within the static
rules method of the data class.