laravel-data icon indicating copy to clipboard operation
laravel-data copied to clipboard

Add the ability to optionally merge automatically inferred rules with manual rules

Open CWAscend opened this issue 6 months ago โ€ข 3 comments

๐Ÿ’ช 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? ๐Ÿงช

CWAscend avatar Aug 19 '24 18:08 CWAscend