Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果输入不为空,则需要进行Laravel验证_Laravel_Validation_Required - Fatal编程技术网

如果输入不为空,则需要进行Laravel验证

如果输入不为空,则需要进行Laravel验证,laravel,validation,required,Laravel,Validation,Required,我使用的是laravel,我有一个带有如下规则的申请表: 'postal_code1' => 'required', 'postal_code2' => 'required_with:postal_code1|numeric', 还有一些html <input type="text" name="postal_code1" /> <input type="text" name="postal_code2" /> 但是不工作我找到了解决办法,

我使用的是laravel,我有一个带有如下规则的申请表:

    'postal_code1' => 'required',
    'postal_code2' => 'required_with:postal_code1|numeric',
还有一些html

<input type="text" name="postal_code1" />
<input type="text" name="postal_code2" />

但是不工作

我找到了解决办法,很简单。更改规则如下:

'postal_code2' => 'nullable|required_with:postal_code1|numeric'

在这里,您添加了邮政编码1必填项,但邮政编码1'postal\u code1'=>“必填项”,“postal\u code2'=>“bail\124; required\u with:postal\u code1 | numeric',@JinalSomaiya:不允许为空,因为我需要两种输入,但错误消息只显示一次。@SachinAghera不工作:((如果您同时需要这两个字段,那么为什么不使用simple required?这就是解决方案,但例如,如果“postal_code2”和“postal_code1”都是可空的,则验证不会通过。)。
'postal_code2' => 'nullable|required_with:postal_code1|numeric'