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

Distinct validation rule not working on top-level array #29190

Closed
archy-bold opened this issue Jul 16, 2019 · 2 comments · Fixed by #29499
Closed

Distinct validation rule not working on top-level array #29190

archy-bold opened this issue Jul 16, 2019 · 2 comments · Fixed by #29499
Labels

Comments

@archy-bold
Copy link

  • Laravel Version: 5.6.39
  • PHP Version: 7.1.28
  • Database Driver & Version: mariadb 10.4

Description:

I'm not 100% sure that this is a bug or intended behaviour but I've been validating an array of values as follows:

$array = [
    ['id' => 1],
    ['id' => 2],
];
$rules = [
    '*' => 'array',
    '*.id' => 'required',
];
Validator::make($array, $rules)->validate();

Now if I use the distinct rule on the '*.id' column it doesn't work. However if I put it into a non-top-level property, it does eg

$array = [
    'items' => [
        ['id' => 1],
        ['id' => 2],
    ],
];
$rules = [
    'items' => 'array',
    'items.*.id' => 'required|distinct',
];

I guess the question is, are top-level array validation rules supposed to work like this?

Steps To Reproduce:

Using the following code, the Validator instance will not fire a validation error.

$array = [
    ['id' => 1],
    ['id' => 1],
];
$rules = [
    '*' => 'array',
    '*.id' => 'required|distinct',
];
Validator::make($array, $rules)->validate();
@staudenmeir
Copy link
Contributor

@driesvints This is still an issue in 5.8.29.

@driesvints driesvints added the bug label Jul 18, 2019
@vahiiiid
Copy link

vahiiiid commented Aug 3, 2019

I reproduced it in laravel 5.8 and without '*' => 'array', it works fine!

$array = [
    ['id' => 1],
    ['id' => 1],
];
$rules = [
    '*.id' => 'required|distinct',
];
Validator::make($array, $rules)->validate();

and also it works by changing the order of rules! :

$rules = [
    '*.id' => 'required|distinct',
    '*' => 'array',
];

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