graphql-laravel: Laravel's custom rules are not working on rules function of a mutation.
Versions:
- graphql-laravel Version: 1.22
- Laravel/Lumen Version: 5.8.*
- PHP Version: 7.1.3
Question:
I created a custom rule for my validation and applying it on rules function of a mutation doesnt work.
code:
public function rules(array $args = []) {
return [
'name' => [
'unique:msp_branches,name,'.$args['id'],
new EmptyStringRule //custom rule
]
];
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15
Thanks for the clarification.
What you’re describing is the expected behavior of the Laravel validation.
Custom validations using
Validator::extendor rule objects implementing\Illuminate\Contracts\Validation\Ruleare skipped for empty attributes.To still have them applied, you need to use
Validator::extendImplictor implement the\Illuminate\Contracts\Validation\ImplicitRuleinterface.Please read up the chapter about Implicit Extensions:
Unfortunately the docs don’t mention that this is also possible/available for rule objects => I’ve created https://github.com/laravel/docs/pull/5237 to clarify this.
I’ve found a source which describes this quite practically: https://laravel-news.com/custom-validation-rule-objects (but I understand you have to be even ware this concept exists to notice it).
Closing the issue as it’s unrelated to this library; thanks for reporting!