framework
framework copied to clipboard
[12.x] Preserve numeric keys on the first level of the validator rules
Fixes #51499 without changing the merge behavior (see testMergeRules in the PR that #39368 wouldn't have passed), simply preserve all the keys passed to the validator rules
Bug description
Running the following in a tinker session
Validator::validate(['foo' => 'baz', 4 => 'foo', 8 => 'baz'], ['foo' => 'required', 4 => 'required', 8 => 'required']);
Results in
Illuminate\Validation\ValidationException The 0 field is required. (and 1 more error).
Because array_merge_recursive rekeys any numeric keys it encounters
array_merge_recursive([], ['foo' => 'required', 4 => 'required', 8 => 'required']);
= [
"foo" => "required",
0 => "required",
1 => "required",
]