Laravel 5.4 required if validation issue

两盒软妹~` 提交于 2021-01-28 09:50:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!