如何解决方法 Illuminate\Validation\Validator::validateVideo 不存在
我正在尝试上传带有 dropzone 的视频,我在控制器、视图、模型、特征等中做了方法......但是当我调用我的函数的路由时,返回了这个:
Method Illuminate\Validation\Validator::validateVideo does not exist.
我明白我的问题在哪里...
我附上了我的实际代码:
路线
Route::post('uploads/storeVideo','UploadController@storeVideo')->name('medias.createVideo');
控制器
public function storeVideo(UploadRequest $request)
{
$input = $request->all();
try {
$upload = $this->uploadRepository->create($input);
$upload->addMedia($input['file'])
->withCustomProperties(['uuid' => $input['uuid'],'user_id' => auth()->id()])
->toMediaCollection($input['field']);
} catch (ValidatorException $e) {
return $this->sendResponse(false,$e->getMessage());
}
}
查看
<div class="form-group row">
{!! Form::label('video',trans("lang.restaurant_video"),['class' => 'col-3 control-label text-right ']) !!}
<div class="col-9">
<div style="width: 100%" class="dropzone video" id="video" data-field="video">
<input type="hidden" name="video">
</div>
<a href="#loadMediaModal" data-dropzone="video" data-toggle="modal" data-target="#mediaModal" class="btn btn-outline-{{setting('theme_color','primary')}} btn-sm float-right mt-1">{{ trans('lang.media_select')}}</a>
<div class="form-text text-muted w-50">
{{ trans("lang.restaurant_video_help") }}
</div>
</div>
</div>
@prepend('scripts')
<script type="text/javascript">
var var15671147011688676454bleVideo = '';
@if(isset($restaurant) && $restaurant->hasMedia('video'))
var15671147011688676454bleVideo = {
name: "{!! $restaurant->getFirstMediaVideoUrl('video')->name !!}",size: "{!! $restaurant->getFirstMediaVideoUrl('video')->size !!}",type: "{!! $restaurant->getFirstMediaVideoUrl('video')->mime_type !!}",collection_name: "{!! $restaurant->getFirstMediaVideoUrl('video')->collection_name !!}"
};
@endif
var dz_var15671147011688676454bleVideo = $(".dropzone.video").dropzone({
url: "{!! url('panel/uploads/storeVideo') !!}",/*dictDefaultMessage: "{{trans('validation.dropzone_dictDefaultMessage')}}",dictFallbackMessage: "{{trans('validation.dropzone_dictFallbackMessage')}}",dictFallbackText: "{{trans('validation.dropzone_dictFallbackText')}}",dictFileTooBig: "{{trans('validation.dropzone_dictFileTooBig',[ 'size' => config('medialibrary.max_file_size') / 1024 / 1024 ])}}",dictInvalidFileType: "{{trans('validation.dropzone_dictInvalidFileType')}}",dictResponseError: "{{trans('validation.dropzone_dictResponseError')}}",dictCancelUpload: "{{trans('validation.dropzone_dictCancelUpload')}}",dictCancelUploadConfirmation: "{{trans('validation.dropzone_dictCancelUploadConfirmation')}}",dictRemoveFile: "{{trans('validation.dropzone_dictRemoveFile')}}",*/
dictMaxFilesExceeded: "{{ trans('validation.dropzone_dictMaxFilesExceeded') }}",maxFilesize: {!! config('medialibrary.max_file_size_video') / 1024 / 1024 !!},acceptedFiles: "video/*",addRemoveLinks: true,maxFiles: 1,init: function () {
@if(isset($restaurant) && $restaurant->hasMedia('video'))
dzInit(this,var15671147011688676454bleVideo,'{!! url($restaurant->getFirstMediaVideoUrl('video','mp4')) !!}')
@endif
this.on("error",function(file,message) {
console.log(message);
$('.video').after(`<ul class="alert alert-danger" style="list-style: none;">
<li>
${message}
</li>
</ul>`);
this.removeFile(file);
});
this.on("success",message) {
$('.alert-danger').remove();
$('.video').after(`<ul class="alert alert-success" style="list-style: none;">
<li>
{{trans('validation.dropzone_success')}}
</li>
</ul>`);
});
},accept: function (file,done) {
dzAccept(file,done,this.element,"{!! config('medialibrary.videos_folder') !!}");
},sending: function (file,xhr,formData) {
dzSending(this,file,formData,'{!! csrf_token() !!}');
},maxfilesexceeded: function (file) {
dz_var15671147011688676454bleVideo[0].mockFile = '';
dzMaxfile(this,file);
},complete: function (file) {
dzComplete(this,dz_var15671147011688676454bleVideo[0].mockFile);
dz_var15671147011688676454bleVideo[0].mockFile = file;
},removedfile: function (file) {
dzRemoveFile(
file,'{!! url("panel/restaurants/remove-media") !!}','video','{!! isset($restaurant) ? $restaurant->id : 0 !!}','{!! url("panel/uploads/clear") !!}','{!! csrf_token() !!}'
);
}
});
dz_var15671147011688676454bleVideo[0].mockFile = var15671147011688676454bleVideo;
dropzoneFields['video'] = dz_var15671147011688676454bleVideo;
</script>
@endprepend
laravel 中的默认上传请求
public function rules()
{
return [
'file' => 'image|video|mimes:jpeg,png,jpg,gif,svg,mp4,mov,avi,mkv',];
}
模型
// VIDEO AND ALLOWED TYPES
public function getFirstMediaUrlVideo($collectionName = 'default',$conversion = '')
{
$url = $this->getFirstMediaVideoUrlTrait($collectionName);
if($url){
$array = explode('.',$url);
$extension = strtolower(end($array));
if (in_array($extension,['.mp4','.mkv'])) {
return asset($this->getFirstMediaVideoUrlTrait($collectionName,$conversion));
} else {
return asset('videos/' . $extension . '.mp4');
}
}else{
return asset('videos/video_default.mp4');
}
}
感谢大家的帮助,我不知道为什么会这样。谢谢
解决方法
您的错误,至少是第一个,在这里:
public function rules()
{
return [
'file' => 'image|video|mimes:jpeg,png,jpg,gif,svg,mp4,mov,avi,mkv',]; ^^^^^
}
没有 video
验证规则(您可以查看完整列表 here)。相反,您应该做的是单独使用 mimes
(或 mimetypes
)规则:
return [
'file' => 'mimes:mp4,];
有关您可以使用的 mime 扩展的完整列表,here's the list。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。