laravel-data
laravel-data copied to clipboard
Add the ability to optionally merge automatically inferred rules with manual rules
๐ช Motivation
I would like the ability to use a combination of Attribute rules and manual rules that are defined within the static rules
method in a Data
object. For me, this will massively clean up my rules method when I have to reach for it, such as which I might be reaching for a callable
rule, or using the Rule::in()
rule where the array is dynamic - just to name some examples.
๐ Changes
- Added a new
Spatie\LaravelData\Attributes\MergeRules
attribute - This will merge the rules from the rules method rather than overwriting them
- Example usage can be found in the test Data class here:
tests/Fakes/DataWithMergedRuleset.php
๐งช Testing
- A new test has been created:
it will merge validation rules
, which ensures both validation rules from the Attributes and the rules method are picked up. - A new test has been created:
it will merge validation rules using string rules
which ensures the validation rules can be a piped string of rules instead of an array of files for each attribute
๐ง Reminders (Author)
- [x] Have you read through your own diff? ๐
- [x] Are all tests passing? ๐งช