我有两个字段:价格和货币。我想做依赖验证如果价格=需要空货币字段,如果是货币=空价格字段是必需的,我想检查价格字段是否为数字。 如果两个字段都为空,并且两个字段都不是必需的。我想在laravel 5.3中进行验证
$this->validate($request,[ 'price'=>'numeric', 'price'=>'required_if:currency,nullable', 'currency'=>'required_if:price,not nullable', ]);
您可以使用 required_with 为了这个。
required_with
$this->validate($request,[ 'price'=>'required_with:currency|numeric', 'currency'=>'required_with:price', ]);