在我的表单中有动态选择,我通过Laravel 5使用Request
类验证它们:
$rules = [
'address' => 'sometimes|required|max:70',
'area' => 'sometimes|required|numeric|max:10000',
];
foreach ($this->request->get('category') as $key => $val) {
$rules['category.' . $key] = 'sometimes|required|exists:categories,id';
}
但验证错误我无法更改并显示如下内容:
Field category.0 is required
,我尝试更改custom
文件中的validation.php
数组,如下所示:
'custom' => [
'category.0' => [
'required' => 'Category is required field'
],
但它没有改变任何东西。
答案 0 :(得分:1)
为数组输入设置自定义验证消息(在我的情况下选择)
我在messages()
类中使用了Request
方法:
public function messages(){
$messages = [];
foreach ($this->request->get('category') as $key => $val) {
$messages['category.'.$key.'.required'] = 'Выберите подраздел';
}
return $messages;
}