【问题标题】:field validation for other field is not null其他字段的字段验证不为空
【发布时间】:2017-11-03 09:27:07
【问题描述】:

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

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

【问题讨论】:

    标签: laravel laravel-5 laravel-5.3


    【解决方案1】:

    您可以为此使用required_with

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      相关资源
      最近更新 更多