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.3] Fix an issue with sometimes when it comes to wildcard rules #16826

Merged
merged 2 commits into from
Dec 16, 2016
Merged

[5.3] Fix an issue with sometimes when it comes to wildcard rules #16826

merged 2 commits into from
Dec 16, 2016

Conversation

themsaid
Copy link
Member

$data = [
    "cities" => [
        [
            "name" => ["NY"]
        ]
    ]
];

$validator = Validator::make($data, [
    "cities.*.name" => "sometimes|required|string",
]);

Currently the validation will pas even though the name is an array instead of a string, that's because cities.0.name doesn't exist when sometimes checks for it in passesOptionalCheck().

This PR fixes that by appending wildcard keys to the $data array before the check.

$data = array_merge($data, $this->extractValuesForWildcards(
$data, $attribute
));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@themsaid $data is needed only when the attribute has sometimes rule. Could you move data extraction logic inside if condition?

@taylorotwell taylorotwell merged commit f5c8c1b into laravel:5.3 Dec 16, 2016
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.

3 participants