-
Notifications
You must be signed in to change notification settings - Fork 771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional Validation: More then "when" #1348
Comments
The $cars = [
['manufacturer' => 'Honda', 'model' => 'Accord'],
['manufacturer' => 'Toyota', 'model' => 'Rav4'],
['manufacturer' => 'Ford', 'model' => 'notarealcar'],
['manufacturer' => 'Honda', 'model' => 'not valid'],
];
try {
Validator::arrayType()->each(
Validator::oneOf(
Validator::key('manufacturer', Validator::equals('Honda'))
->key('model', Validator::in(['Accord', 'Fit'])),
Validator::key('manufacturer', Validator::equals('Toyota'))
->key('model', Validator::in(['Rav4', 'Camry'])),
Validator::key('manufacturer', Validator::equals('Ford'))
->key('model', Validator::in(['F150', 'Bronco']))
)
)->assert($cars);
} catch (NestedValidationException $e) {
var_dump($e->getMessages());
} This behaves like an While testing this, I noticed that my recent changes to Each were broken for this example. It should, however, work for |
I'm closing this because it was supported before. There is an improvement related to it, but it is about the message reporting in |
Some templates were a bit confusing, and I would like to favour adding the `{{name}}` at the beginning of the templates as it helps when reading nested messages. I also deleted the regression tests for issue Respect#1348, because it's a non-issue, actually. The best approach to that problem is indeed using `When` insteaf of `OneOf`.
Some templates were a bit confusing, and I would like to favour adding the `{{name}}` at the beginning of the templates as it helps when reading nested messages. I also deleted the regression tests for issue Respect#1348, because it's a non-issue, actually. The best approach to that problem is indeed using `When` insteaf of `OneOf`.
When is a great rule for a binary case. Is there a rule or way to do conditional validation if the conditional key value can have more than two outcomes?
e.g.
This code works, but chaining 'when' gets a little cumbersome after a few 'manufacturers'. Is there some kind of switch-like rule?
The text was updated successfully, but these errors were encountered: