这是我的验证规则:
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.',
];
}
虽然在填写表格时上传频道图片不是强制性的,但image
验证规则的channelImage
工作方式好像是强制性的,即我每次提交请求时都需要上传图片。
为什么会这样工作??我没有提到required
规则,为什么当我不上传任何图像时channelImage
它仍在验证?channelImage