field validation for other field is not null

Viewed 13100

I have 2 fields price and currency.I want to make dependency validation if price!=null currency field is required and if currency!=null price field is required as well as I want to check price field is numeric. if both field is null and that both field is not required.I want to validate in laravel 5.3

$this->validate($request,[
  'price'=>'numeric',
  'price'=>'required_if:currency,nullable',
  'currency'=>'required_if:price,not nullable',
]);
1 Answers

You can use required_with for this.

$this->validate($request,[
  'price'=>'required_with:currency|numeric',
  'currency'=>'required_with:price',
]);
Related