[英]Can I change a Laravel error message globally?
我可以在請求中做這樣的事情。
public function messages()
{
return [
'title.required' => 'A title is required',
'body.required' => 'A message is required',
];
}
但我仍然覺得我會重復很多代碼,因為在我的情況下,我還會針對不同的錯誤和字段重復許多相同的錯誤消息。 那么有沒有辦法修改required
的error,比如整個項目的scope呢?
如果這就是您的意思,您可以覆蓋 resources/lang/[lang]/validation.php 文件中的默認驗證語言行。
例如,您可以找到以下行:
'required' => 'The :attribute field is required.'
並將其更改為您想要說的任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.