-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
RequiredIf validator with multiple values fails validating boolean 0 #36952
Comments
It only triggers Validator::make(['some_bool_field' => 0], [
'some_bool_field' => 'required|boolean',
'check_against_1' => 'required_if:some_bool_field,1,true',
'check_against_2' => 'required_if:some_bool_field,0,false',
]); {
"check_against_2": [
"The check against 2 field is required when some bool field is 0."
]
} |
@driesvints for which Laravel version? Doing exactly what you did: Route::get('test', function(){
Validator::make(['some_bool_field' => 0], [
'some_bool_field' => 'required|boolean',
'check_against_1' => 'required_if:some_bool_field,1,true',
'check_against_2' => 'required_if:some_bool_field,0,false',
])->validate();
}); And the response: {
"message": "The given data was invalid.",
"errors": {
"check_against_1": [
"The check against 1 field is required when some bool field is 0."
],
"check_against_2": [
"The check against 2 field is required when some bool field is 0."
]
}
} |
@Norgul I get a validation exception for that code. Laravel v8.36.2 |
@driesvints you are doing it wrong. You are dumping the current rule only. Run my exact route to reproduce. |
I did run your exact code. |
@driesvints but you are showing a dump, not a response? |
This is the validation exception I get when calling the |
@driesvints Try putting it within |
If you call this within the API middleware with the correct For example:
Returns
Whereas
Returns
However, the behaviour is different when running PHP 8 vs PHP 7.4. PHP 8 correctly evaluates the string values |
Description:
Since
boolean
validation rule accepts and validates several boolean value variants I wanted to enablerequired_if
validator to accept and validate against those values as well, however it fails having0
as a value.Steps To Reproduce:
Correct behavior 1:
Correct behavior 2:
Invalid behavior:
The text was updated successfully, but these errors were encountered: