requiredWithout rule is broken for multi dimensional array of data.
sumitkohli1989 opened this issue · 2 comments
sumitkohli1989 commented
fields with DOT (.) not working
$validationBody->rule('requiredWithout', 'card.id', ['card.name', 'card.expiryMonth', 'card.expiryYear', 'card.number']);
$validationBody->rule('requiredWithout', 'card.number', ['card.id'])->rule('numeric', 'card.number');
$validationBody->rule('requiredWithout', 'card.name', ['card.id'])->rule('alphaNumSpace', 'card.name');
awprice commented
+1 I've run into this too. Would be great to get this working.
eugene-borovov commented
Quick fix
use Adbar\Dot; // adbario/php-dot-notation
use Valitron\Validator;
class FormValidator extends Validator
{
protected function validateRequiredWith($field, $value, $params, $fields): bool
{
return parent::validateRequiredWith($field, $value, $params, (new Dot($fields))->flatten());
}
protected function validateRequiredWithout($field, $value, $params, $fields): bool
{
return parent::validateRequiredWithout($field, $value, $params, (new Dot($fields))->flatten());
}
}