映像验证规则未按预期工作



这是我的验证规则:

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.',
];
}

虽然,在填写表单时上传频道图像不是强制性的,但channelImageimage验证规则就像是强制性的一样工作,即我每次提交请求时都需要上传图像。

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

尝试使用nullable

'channelImage' => 'nullable|image',

最新更新