-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
Description
Hi there, first of all thanks for a great library.
I have a question about conditional validation, because my biggest problem is that the library is completely dependent on array keys.
Here is what I need:
$validator->when(function (array $values) { return isset($values['key1']); })->require('key2')->string();I can add a new rule When which will check if one or another key is set and validate it there, but how can I require or skip a key when there is or not another key set ?
Here is how I do it atm:
$validator->optional('key')->callback(function ($value, array $values) use ($validator) {
if (!isset($values['hey2']) || empty($values['hey2'])) {
$validator->required('key')->string();
}
return true;
});Is there a better way ?
Thanks!