Rule inferrers automatically generate validation rules for properties within a data object.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spatie/laravel-data/llms.txt
Use this file to discover all available pages before exploring further.
RuleInferrer Interface
Implement theRuleInferrer interface:
Parameters
- property -
DataPropertyobject representing the property (read more) - rules -
PropertyRulescollection of previously inferred rules - context -
ValidationContextcontaining:payload- Current payload for the data object being validatedfullPayload- Full payload being validatedvalidationPath- Path from full payload to current payload
Working with PropertyRules
Adding Rules
Automatic Rule Replacement
When adding a rule of the same type, the previous version is removed:Adding String Rules
Checking for Rule Types
Removing Rules
Example Implementation
Registration
Rule inferrers must be registered in theconfig/data.php config file:
Return Value
A rule inferrer must always return a
PropertyRules collection.