[4.x] Support for validation Rule objects #9332
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Laravel 10 has marked the existing
Illuminate\Contracts\Validation\Rule
as deprecated, and new rules are created usingIlluminate\Contracts\Validation\ValidationRule
, which can't be added to Laravel's Validator using theextend
method (unless I'm missing something).This PR adds support for a new syntax for using your own custom rules for Blueprint validation.
You can make your Laravel Rule as per Laravel's docs, such as:
In the YAML or Blueprint editor, you can attach this rule to the validation using the
rule:
prefix:This also supports rules that have custom parameters:
Params are in the
key:value
syntax, with multiple separated by commas. Such as:rule:{class}:{keyA}:{valueA},{keyB}:{valueB},{keyC}:{valueC}
rule:\App\Rules\MyCustomRule:varA:valueA,varB:valueB
This will call the MyCustomRule, and pass
valueA
andvalueB
as the parameters.There may be a neater way to handle the parameters but this keeps it as open-ended as possible for the user's rule implementation.