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

Validating arrays with distinct rule involves attributes in nested arrays #16987

Closed
denho opened this issue Dec 26, 2016 · 1 comment
Closed

Comments

@denho
Copy link

denho commented Dec 26, 2016

  • Laravel Version: 5.3.22
  • PHP Version: 7.0.10

Description:

In docs for distinct validation rule it is written: "When working with arrays, the field under validation must not have any duplicate values.". But it checks not only the exactly the matching field, but all nested fields with the same attribute name. E.g. 'foo.*.id' => 'distinct' will check not only foo.0.id, foo.1.id,.. but also foo.0.nested.id.
The reason is that Str::is($attributeName, $key) matches not only foo.0.id or foo.1.id, but also foo.0.whatever.id

Steps To Reproduce:

$array = [
 'foo' => [
    ['id' => 1, 'nested' => ['id' => 2]],
    ['id' => 2],
  ]
];

$validator = Validator::make($array, [
  'foo.*.id' => 'distinct'
]);

if($validator->fails())
 dd($validator->errors());

will fail and return "The foo.1.id field has a duplicate value."

@themsaid
Copy link
Member

themsaid commented Jan 3, 2017

Thank you, submitted a fix in this PR: #17102

@themsaid themsaid closed this as completed Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants