Home >Backend Development >PHP Tutorial >Laravel验证表单自定消息写那里?

Laravel验证表单自定消息写那里?

WBOY
WBOYOriginal
2016-06-06 20:13:591073browse

  • 我是直接在store()调用表单验证的,例如

<code>  public function store(Requests\HrFormRequest $request)</code>
  • 这样调用表单验证,怎么去自定义错误消息呢?

文档里写的

<code>$messages = [
    'email.required' => 'We need to know your e-mail address!',
];</code>

这个$messages应该放那里..因为是在store()的参数直接调用表单验证,所以不知道放那里.

回复内容:

  • 我是直接在store()调用表单验证的,例如

<code>  public function store(Requests\HrFormRequest $request)</code>
  • 这样调用表单验证,怎么去自定义错误消息呢?

文档里写的

<code>$messages = [
    'email.required' => 'We need to know your e-mail address!',
];</code>

这个$messages应该放那里..因为是在store()的参数直接调用表单验证,所以不知道放那里.

在别的地方有人回复了答案,按我的文件为例应该写在.

<code>File: Requests\HrFormRequest.php</code>
<code>public function messages() {
$messages = [
    'email.required' => 'We need to know your e-mail address!',
];
return $messages
}</code>

或者

<code>  public function messages()
  {
    return [
    'email.required' => 'We need to know your e-mail address!',
    ];
  }</code>

需要注意的是,字段后的规则是对应自定义错误消息的.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn