问题
I have 2 fields, accepts_usd and price_usd.
For price usd I have a validation rule:
'price_usd'=>'integer|required_if:accepts_usd,1',
And for accepts_usd:
'accepts_usd'=>'boolean|required',
When I want to store data if I set accepts_usd to false it still asks for price_usd.
whats the issue here? What am I doing wrong?
回答1:
you need to change your code to
'price_usd'=>'integer|required_if:accepts_usd,==,1',
回答2:
From laravel docs: required_if:anotherfield,value,...
The field under validation must be present and not empty if the anotherfield field is equal to any value.
Value is not an actual value, its another validation rule.
回答3:
Try 'price_usd'=>'integer|required_if:accepts_usd,==,1',
As mentioned in laravel docs :
required_if:anotherfield,value,...
The field under validation must be present and not empty if the anotherfield field is equal to any value.
来源:https://stackoverflow.com/questions/42931659/laravel-5-4-required-if-validation-issue