【发布时间】:2018-08-15 07:51:44
【问题描述】:
使用 laravel 5.4 我有 2 个字段: kg_bags 和 g_bags
其中至少一个必须具有大于零的正值。
如何更改所需的验证_无需这样做?
如果我将零或 -value 放在一个中而另一个中没有,我不会收到错误,这是错误的。
如果我在 kg_bags 中输入 -1 而在 g_bags 中不输入任何内容,我也不会收到错误,但代码会失败,因为它不能使用负值。
我的代码:
if($request->kg_bags) {
$this->validate($request,[
"kg_bags" => "numeric"
]);
}
if($request->g_bags)
{
$this->validate($request,[
"g_bags" => "numeric"
]);
}
$this->validate($request,[
"kg_bags" => "required_without:g_bags",
"g_bags" => "required_without:kg_bags"
],
[
'kg_bags.required_without' => 'Please fill in the number of bags you packed',
'g_bags.required_without' => 'Please fill in the number of bags you packed',
]);
【问题讨论】:
标签: validation laravel-5