This is the documentation for
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-data
Rule inferrers will try to infer validation rules for properties within a data object.
A rule inferrer can be created by implementing the
public function handle(DataProperty $property, RulesCollection $rules): array;
A collection of previous inferred rules is given, and a
DataProperty object which represents the property for which the value is transformed. You can read more about the internal structures of the package here.
RulesCollection contains all the rules for the property represented as
You can add new rules to it:
When adding a rule of the same kind, a previous version of the rule will be removed:
$rules->all(); // [new Min(314)]
Adding a string rule can be done as such:
You can check if the collection contains a type of rule:
Or remove certain types of rules:
In the end, a rule inferrer should always return a
Rule inferrers need to be manually defined within the
data.php config file.