-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Validation rule "in" doesn't work with "sometimes" #16711
Comments
this is correct. |
@themsaid Let say the array of choices should be a string $data = [
"response" => [
[
"choices" => [40]
]
]
];
$rules = [
"response.*.choices" => "sometimes|required|string"
]; Validation doesn't fail for this rule set too. |
You need to use this:
All arrays will be flattened inside the validator, that's why you need to handle this edge case in a special way, so your last work around is the way to go yes. |
@themsaid In my previous example, I was trying to demonstrate the Now I want to the validate the Expected data structure $data = [
"response" => [
[
"choices" => "NY"
]
]
]; Instead of string, what if the Received data structure $data = [
"response" => [
[
"choices" => ["NY"]
]
]
]; Should |
@themsaid do you need any additional info to replicate this issue or should I need to create new issue for my second scenario? |
I've submitted a fix for that: #16826 Thank you :) |
@themsaid OSM!!!. This fix resolved my issue on both scenarios. this fix will be merged to 5.2 as well? |
Description:
There is an inconsistency when I use validation rule
in
with and withoutsometimes
.Steps To Reproduce:
Data for validation
Rule without
sometimes
If I run this rule against the data, it fails and produces a message like
But if I use
sometimes
along with other validation rule for choices, the validation doesn't fail as expected.After debugging, I found the root cause for this issue. The key
response.0.choices
does not exists, when validator checks for existence in dot notation data array.https://github.com/laravel/framework/blob/5.2/src/Illuminate/Validation/Validator.php#L590
Right now I'm using this work around to solve this issue
The text was updated successfully, but these errors were encountered: