laravel 5.4 custom error message for MIME not working?

☆樱花仙子☆ 提交于 2019-12-11 05:18:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!