Framework: Validation rule "in_array" returns failure when success expected

Created on 26 Oct 2016  路  1Comment  路  Source: laravel/framework

  • Laravel Version: 5.2,5.3
  • PHP Version: 7.08
  • Database Driver & Version: Not Relevant

    Description:

By Laravel documentation the validation rule "in_array", should validate whether a fields value under validation exist as an array value in a different field:
"The field under validation must exist in anotherfield's values."

By checking a simple case it does not seem to do so, in any case I have no understanding what this validation rule actually does. Now, this may be just me misunderstanding something, bet here are the steps to reproduce

Steps To Reproduce:

$input = [
    'locales' => ['EN', 'FR', 'RU'],
    'locale' => 'EN'
];


$validation = Validator::make($input, [
   'locale' => 'in_array:locales',
]);
$validation->fails(); /* returns true, expected false */

(v5.3.20/src/Illuminate/Validation/Validator.php in line 1053)
By taking a look at the source, the problem arises in calling Arr::dot on $attributeData
which produces an array like this ['locales.0.' => 'EN', ..., ...], that will never be
equal to "locales", therefore the closure of Arr::where will return an empty array;

Most helpful comment

use in_array:locales.*

>All comments

use in_array:locales.*

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YannPl picture YannPl  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

jackmu95 picture jackmu95  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

shopblocks picture shopblocks  路  3Comments