Skip to content
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

Validation of array children always considered "required"? #262

Closed
ecker00 opened this issue Aug 19, 2018 · 1 comment
Closed

Validation of array children always considered "required"? #262

ecker00 opened this issue Aug 19, 2018 · 1 comment
Assignees
Labels

Comments

@ecker00
Copy link

ecker00 commented Aug 19, 2018

The validator seems to behave differently when validating a "root" value compared to an array child. Given the data:

$input = [
  'myObjs' => [
    ['myDate'=>'2018-01-01'],
    ['stuff'=>true]
  ]
];
$v = new Validator($input);
$v->rule('date', 'myObjs.*.myDate');
if (!$v->validate()) echo $v->errors(); # = Invalid date

Will say that date is invalid, as it is not present on the second object. While evaluating them individually it does not matter that date is missing (unless it's specified as required).

$input = ['date'=>'2018-01-01'];
$v = new Validator($input);
$v->rule('date', 'myDate');
if (!$v->validate()) echo $v->errors(); # = All ok

Is this intentional?

@willemwollebrants
Copy link
Collaborator

Looks like a bug to me, I'll look into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants