其他字段的字段验证不为空

field validation for other field is not null

我有 2 个字段 price 并且 currency.I 如果 price!=null currency 字段是必需的并且如果 currency!=null price 字段是必需的并且我想检查 price 字段是数字。 如果两个字段都为空并且两个字段都不是 required.I 想要在 laravel 5.3

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

您可以使用 required_with 来实现。

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