Laravel 图像验证规则未按预期工作

Laravel 图像验证规则未按预期工作,laravel,laravel-5,laravel-validation,validationrule,Laravel,Laravel 5,Laravel Validation,Validationrule,以下是我的验证规则: public function rules() { $channel_id = Auth::user()->channels->first()->id; return [ 'name' => 'required|max:30|unique:channel,name,' . $channel_id, 'slug' => 'required|max:30|alpha_num|unique:chann

以下是我的验证规则:

public function rules() {

    $channel_id = Auth::user()->channels->first()->id;
    return [
        'name' => 'required|max:30|unique:channel,name,' . $channel_id,
        'slug' => 'required|max:30|alpha_num|unique:channel,slug,' . $channel_id,
        'description' => 'max:1000',
        'channelImage' => 'image',

    ];
}

public function messages() {
    return [

        'slug.unique' => 'That  unique URL has already been taken.',
        'channelImage.image' => 'Only jpeg, jpg, png, bmp, gif and svg formats are supported.',
    ];
}
虽然填写表单时上传频道图像不是强制性的,但是
channelImage
image
验证规则的工作原理与强制性的一样,即每次提交请求时我都需要上传图像

为什么要这样工作??我没有提到
channelImage
required
规则,但为什么在我不上传任何图像时它会验证
channelImage

尝试使用:


尝试此“channelImage”=>“nullable | image”“channelImage”=>“nullable | image”不起作用直到不起作用:(您可能将视图上的验证与此后端验证分开?@PritamBohra您是否添加了
enctype=“多部分/表单数据”
表单中的
?'channelImage'=>'nullable | image'不起作用。我没有downvote@Leo,如果你投了反对票,你介意告诉我为什么吗?
'channelImage' => 'nullable|image',