laravel数组需要验证每个被触发的事件值是否存在?

时间:2016-05-24 05:32:06

标签: php validation laravel-5

下面是我的验证码。

$rules = [
    'other_feature[]' => required
];

$message = [
     'other_feature[].required' => 'The other feature field is required.',
];

$this->validate($request, $attributes_validation, $attributes_message);
$result = $this->UploadRepo->updateUploadValue($data,$id);
<_>在other_feature中传递多重选择值,如。

<select name='other_feature[]' multiple>
   <option>First</option>
   <option>Second</option>
   <option>Third</option>
   <option>Four</option>
   <option>Five</option>
</select>

我在验证中创建了一个错误,为什么每次即使我选择值也会触发空验证,请帮忙。

由于

1 个答案:

答案 0 :(得分:1)

我认为你应该放弃它[]它没用。根据请求,您只需获得多个选定选项的数组,因此您无需将括号留在那里。你可以做的是验证它是否为数组。

$rules = [
    'other_feature' => 'required|array'
];

$message = [
     'other_feature.required' => 'The other feature field is required.',
];