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

[5.2] Validate array size of implicit attributes #12640

Merged
merged 1 commit into from
Mar 28, 2016
Merged

[5.2] Validate array size of implicit attributes #12640

merged 1 commit into from
Mar 28, 2016

Conversation

themsaid
Copy link
Member

@themsaid themsaid commented Mar 5, 2016

Currently there's no way to validate the size of an array in an implicit attribute:

Validator::make(
    ['foo' => [['bar' => [1, 2, 3]], ['bar' => [1, 2, 3]]]], 
    ['foo.*.bar' => 'size:4']
);

The case is the same with size, between, min, and max.

The reason is that inside the each method all arrays are flattened, so no key will ever has an array value for these rules to work.

$data = Arr::dot($this->initializeAttributeOnData($attribute));

This PR appends exact values for the attribute for each iteration at the end of the $data variable.

NOTE

For these changes to pass the unit tests I had to remove the ValidationValidatorTest::testValidateEach() tests, they hit the each() method directly with invalid validation rules that won't work if applied to the Validator::make() method, and since exact values are now appended to the $data variable these tests will no longer succeed.

@themsaid themsaid changed the title [5.2] Validate array size [5.2] Validate array size of implicit attributes Mar 5, 2016
@taylorotwell taylorotwell merged commit 5d09bb9 into laravel:5.2 Mar 28, 2016
@seleznevdev
Copy link

@themsaid, you're the King of Validation 👑

@themsaid themsaid deleted the validate-size-with-arrays branch March 28, 2016 16:48
@themsaid
Copy link
Member Author

@seleznevdev haha .. thank you :)

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.

None yet

3 participants