Laravel validation message for max size is incorrect

47 views Asked by At

I'm currently facing this issue where I want to use the max key when I upload a file. But then it returns a different message. The max key returns the uploaded message instead of the max message. I know I can use the uploaded key but this key is for validation when the file was not successfully uploaded. [Other reference].

Code

public function rules()
{
    return [
        'image' => 'required|max:2048|file|mimetypes:image/jpg,image/jpeg,image/png'
    ];
}

public function messages()
{
    return [
        'image.max' => 'The image file size must not be greater than 2Mb.'
    ];
}

Expected

The image file size must not be greater than 2Mb.'

Result

The image failed to upload.

0

There are 0 answers