【发布时间】:2015-09-01 14:43:26
【问题描述】:
我正在为 Laravel 5 开发带有自定义错误消息的自定义请求验证器。有没有办法可以在返回的消息中显示 HTML?
我的目标是能够在消息中包含链接,即:
"You need a lottery ticket number. Don't have one? <a href='#'>Register Here.</a>"
我搜索了不同的论坛,但找不到解决方案。以下不适用于我的情况: https://laracasts.com/discuss/channels/general-discussion/html-in-httprequests-custom-error-messages
编辑:
已解决。
我正在使用自定义请求中设置的自定义消息:
public function messages()
{
return [
'dob.eighteen' => 'You must be 18 or older to take part in this competition.',
'photo.required' => 'You must upload a photo of the space.',
'photo.mimes' => 'The uploaded file must be a photo in .jpeg or .png format.',
'name.required' => 'Please enter your full name.',
'ticket.required' => 'You need a ticket number to enter. Don\'t have one? <a href="#">Register Here.</a>',
'email.required' => 'The e-mail field is required.',
'dob.required' => 'The date of birth is required.',
'postcode.required' => 'The date of birth is required.',
'postcode.postcode' => 'The postcode you entered is incorrect.', ];
}
上述链接不适用的原因是因为我想保持我的代码整洁并将所有错误消息与请求验证规则一起存储在一个文件中。
解决方案非常简单,以至于我之前完全错过了它。
感谢您的帮助。
【问题讨论】:
-
你需要说明为什么它不适用,还有一些代码也会很好,因为到目前为止还没有足够的信息继续下去。
-
您想从表单验证错误中更改消息,还是只想在 html 中返回一般错误消息?
-
仅供参考:如果您自己找到答案,则完全可以自行回答。
标签: php html laravel laravel-5