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

use*_*779 0 laravel laravel-5 laravel-5.3

我有2个字段price和currency.I要进行依赖验证,如果price!= null货币字段是必需的,如果currency!= null price字段是必需的,并且我想检查price字段是否为数字。如果两个字段都为null,并且两个字段都不是必需的。我想在laravel 5.3中进行验证

$this->validate($request,[
  'price'=>'numeric',
  'price'=>'required_if:currency,nullable',
  'currency'=>'required_if:price,not nullable',
]);
Run Code Online (Sandbox Code Playgroud)

Paw*_*mar 5

您可以required_with为此使用。

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