W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
如果有需要,您可以設(shè)置自定義的錯(cuò)誤信息取代默認(rèn)錯(cuò)誤信息。這里有幾種方式可以設(shè)定自定義消息。
傳遞自定義消息進(jìn)驗(yàn)證器
$messages = [
'required' => 'The :attribute field is required.',
];
$validator = Validator::make($input, $rules, $messages);
注意: 在驗(yàn)證中,:attribute 占位符會(huì)被字段的實(shí)際名稱給取代。您也可以在驗(yàn)證信息中使用其他的占位符。
$messages = [
'same' => 'The :attribute and :other must match.',
'size' => 'The :attribute must be exactly :size.',
'between' => 'The :attribute must be between :min - :max.',
'in' => 'The :attribute must be one of the following types: :values',
];
有時(shí)您只想為一個(gè)特定字段指定一個(gè)自定義錯(cuò)誤信息:
$messages = [
'email.required' => 'We need to know your e-mail address!',
];
某些狀況下,您可能希望在語(yǔ)言包文件中設(shè)定您的自定義消息,而非直接將他們傳遞給 Validator。要達(dá)到這個(gè)目的,將您的信息增加至 resources/lang/xx/validation.php 文件的 custom 數(shù)組中。
'custom' => [
'email' => [
'required' => 'We need to know your e-mail address!',
],
],
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: