Skip to content
Advertisement

Laravel 5.4 required if validation issue

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?

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement