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

[11.x] Fixes validation using shouldConvertToBoolean when parameter uses dot notation #53048

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

bytestream
Copy link
Contributor

@bytestream bytestream commented Oct 7, 2024

Given the following validation rules:

['customfield' => ['nullable', 'array'], 'foo' => 'required_if:customfield.1,taylor']

The use of Arr::get() in shouldConvertToBoolean($parameter) results in attributes containing dot notation being parsed. Thus, in the above example, Arr::get($this->rules, 'customfield.1', []) returns array - the second element (zero-indexed) in the customfield validation rules.

The intended behaviour is that it returns all of the validation rules for the customfield.1 attribute.

Without the changes in this PR, the test case fails with the below:

1) Illuminate\Tests\Validation\ValidationValidatorTest::testRequiredIf
TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given

/Users/bytestream/PhpstormProjects/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php:2262
/Users/bytestream/PhpstormProjects/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php:2243
/Users/bytestream/PhpstormProjects/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php:2002
/Users/bytestream/PhpstormProjects/framework/src/Illuminate/Validation/Validator.php:664
/Users/bytestream/PhpstormProjects/framework/src/Illuminate/Validation/Validator.php:459
/Users/bytestream/PhpstormProjects/framework/tests/Validation/ValidationValidatorTest.php:1706

@crynobone crynobone changed the title Fix: shouldConvertToBoolean when parameter uses dot notation [11.x] Fixes validation using shouldConvertToBoolean when parameter uses dot notation Oct 8, 2024
@taylorotwell taylorotwell merged commit b6a5179 into laravel:11.x Oct 8, 2024
33 checks passed
@bytestream bytestream deleted the 11.x-validation branch October 8, 2024 14:58
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

Successfully merging this pull request may close these issues.

2 participants