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

WBOY
Release: 2016-06-06 20:13:59
Original
1056 people have browsed it

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

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

文档里写的

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

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

回复内容:

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

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

文档里写的

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

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

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

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

或者

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

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template