问题
Dearest,
I want to make a custom error message for uploaded image,
here's my controller code :
protected function validator($data = [], $validateContent = []){
$messages = [
'imgUserAvatar:mimes' => 'File Type must be in jpeg,jpg,png'
];
return Validator::make($data, $validateContent, $messages);
}
$validateContent = [
'imgUserAvatar' => 'mimes:jpeg,jpg,png|max:2000',
'textUserEmail' => 'required|unique:admin_user,user_email|max:50',
'textFirstName' => 'required|max:50',
'textLastName' => 'max:50',
'textPwd' => 'required|min:6|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/',
'textPwdConfrim' => 'required|same:textPwd'
];
$validation = $this->validator($request->all(), $validateContent);
but this custom message do not want to show up, the default message shown Image Link
is there something i mistakenly code?
回答1:
You need to use dot
between field and rule, so you should use:
$messages = [
'imgUserAvatar.mimes' => 'File Type must be in jpeg,jpg,png'
];
instead of
$messages = [
'imgUserAvatar:mimes' => 'File Type must be in jpeg,jpg,png'
];
来源:https://stackoverflow.com/questions/43803218/laravel-5-4-custom-error-message-for-mime-not-working