更新时间:2023-02-19 11:30:27
消息为您的字段如下。
$messages = array(
'cat.required' => 'The category field is required.',
);
$validator = Validator::make($input, $rules, $messages);
请参阅 laravel文档中的自定义错误消息部分以获取更多信息。
Please see Custom Error Messages section in laravel documentation for more information.
或者您可以为您的字段名称保留一个映射,如下所示。你可以将这些设置为你的验证器。所以你可以看到描述性的名字,而不是真正的字段名。
Or you can keep a mapping for your field names like below. And you can set those into you validator. So you can see descriptive name instead of real field name.
$attributeNames = array(
'name' => 'Name',
'cat' => 'Category',
);
$validator = Validator::make ( Input::all (), $rules );
$validator->setAttributeNames($attributeNames);