1
我正在使用Laravel 5自定義錯誤消息的自定義請求驗證器。有沒有一種方法可以在返回的消息中顯示HTML?Laravel:在app/http /請求中顯示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.', ];
}
爲什麼上面的鏈接是不適用的原因是因爲我要保持我的代碼整潔,所有的錯誤信息存儲在一個與請求驗證規則一起提交。
解決方案非常簡單,我完全錯過了它。
感謝您的幫助。
您需要指定爲什麼它不適用,也有些代碼會很好,因爲到目前爲止還沒有足夠的信息可以繼續。 – Bogdan
您是否想要更改表單驗證錯誤中的消息,或者您只是想在HTML中返回一條通用錯誤消息? – user2094178
供參考:如果你自己找到答案,自我回答完全可以。 – NightShadeQueen