我正在尝试验证图片上传,如下所示:
$this->validate($request, [
'admin_image'=> 'nullable|image|dimensions:min_width=600,min_height=600',
]);
当所选图像太小时,laravel会显示错误:
The Admin Image has invalid image dimensiona
我认为这个消息并没有具体说明图像在哪个维度上很小,例如:宽度或高度。
我期待如下错误消息:
The Admin Image width cannot be less than 600px
和
The Admin Image height cannot be less than 600px
此处'管理员图片'是属性名称& '600'是我在规则中给出的值
因此,我想在validation.php上的min_width
消息数组中为max_width
和custom
制作一条自定义错误消息,如下所示:
'admin_image' => [
'dimensions.min_width' => 'The :attribute dimension (width) cannot be less than :min_width px',
'dimensions.min_height' => 'The :attribute dimension (height) cannot be less than :min_height px',
],
但不幸的是,这不起作用& Laravel继续显示默认消息。
请理解
dimensions:min_width=600
& dimensions:min_height=600
我知道这很简单,但我做错了。
任何帮助都将受到高度赞赏
答案 0 :(得分:1)
如下所示在validation.php
中添加自定义错误消息:
'admin_image' => [
'dimensions' => [
'min_width' => 'The :attribute dimension (width) cannot be less than :min_width px'
]
]