Laravel 中图像大小规则的自定义验证消息

Gev*_*yan 2 php validation message rules laravel

在我的 CustomFormRequest 文件中,我对图像文件有以下规则:

public function rules() {
        return [
            'image' => 'image|max:2047',
        ];
    }
Run Code Online (Sandbox Code Playgroud)

和适当的验证消息:

public function messages() {
        return [
            'image.image' => 'The type of the uploaded file should be an image.',
            'image.max' => 'Failed to upload an image. The image maximum size is 2MB.',
        ];
    }
Run Code Online (Sandbox Code Playgroud)

但是没有出现最大尺寸规则的消息。显示最大文件大小的默认消息而不是它。我做错了什么?

Gev*_*yan 8

经过几个小时的研究,我终于找到了方法:

public function messages() {
        return [
            'image.image' => 'The type of the uploaded file should be an image.',
            'image.uploaded' => 'Failed to upload an image. The image maximum size is 2MB.',
        ];
    }
Run Code Online (Sandbox Code Playgroud)