代码之家  ›  专栏  ›  技术社区  ›  user3386779

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

  •  13
  • user3386779  · 技术社区  · 7 年前

    我有两个字段:价格和货币。我想做依赖验证如果价格=需要空货币字段,如果是货币=空价格字段是必需的,我想检查价格字段是否为数字。 如果两个字段都为空,并且两个字段都不是必需的。我想在laravel 5.3中进行验证

    $this->validate($request,[
      'price'=>'numeric',
      'price'=>'required_if:currency,nullable',
      'currency'=>'required_if:price,not nullable',
    ]);
    
    1 回复  |  直到 7 年前
        1
  •  22
  •   Pawan Kumar    7 年前

    您可以使用 required_with 为了这个。

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