这是我的验证规则:
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
的{{1}}验证规则就像强制要求一样,即我每次都需要上传图片我提交了请求。
为什么这样工作?我没有提到channelImage
的{{1}}规则,还有为什么在我没有上传任何图片时验证required
的原因?