required_with and required_if rules cannot handle 0 value
See original GitHub issueSample code :
method: 'numeric', description: 'required_with:method|required_if:method,0'
Validations are not triggered when method value is 0.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Required if greater than 0 not working in laravel
I required one field if another field value is greater than 0. I tried like this 'scope' => 'required_if:project,>,1',. This ...
Read more >Validation - Laravel - The PHP Framework For Web Artisans
The Validator class provides several rules for validating files, such as size , mimes , and others. When validating files, you may simply...
Read more >Laravel 9 validation requiredIf and string rules
Hi everyone, I don't know why in laravel 9 the requiredIf rule don't take effect, ... @Sinnbeck a field name, its value can...
Read more >Validation - Laravel guide
Available Validation Rules; Conditionally Adding Rules; Validating Arrays ... Next, let's take a look at a simple controller that handles these routes.
Read more >RequiredAttribute Class (System.ComponentModel. ...
Specifies that a data field value is required. ... RequiredAttribute attribute to override the database schema rule that allows a data field to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can see the point here. Let me stew on this for a bit. My initial thinking is, if the value is required, but an empty string is supplied, theoretically that should fail validation.
Now, on the bad side, if I make this change, then I risk breaking other applications which don’t adopt this strictness
Hi.
The issue comes from the fact that required_if rule takes it’s parameter as string, so what it’s doing is:
0 === '0'
.As a workaround, I used the
registerImplicit
method provided by Validator class: