Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

javascript - Method IlluminateValidationValidator::validateVideo does not exist

i′m traying to upload a video with dropzone, i did method in controller, view, model, trait, etc... But when i call my route to my function, returned me this:

Method IlluminateValidationValidator::validateVideo does not exist.

i understand where i have my problem...

i attachd my actual code:

route

Route::post('uploads/storeVideo', 'UploadController@storeVideo')->name('medias.createVideo');

Controller

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());
        }
    }

view

<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", function(file, 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, file, var15671147011688676454bleVideo, dz_var15671147011688676454bleVideo[0].mockFile);
                            dz_var15671147011688676454bleVideo[0].mockFile = file;
                        },
                        removedfile: function (file) {
                            dzRemoveFile(
                                file, var15671147011688676454bleVideo, '{!! 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

UploadRequest deault in laravel

public function rules()
    {
        return [
            'file' => 'image|video|mimes:jpeg,png,jpg,gif,svg,mp4,mov,avi,mkv',
        ];
    }

Model

// 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');
        }
    }

thanks for all help, i don′t know why does this happen. Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your error, at least the first one, is here:

public function rules()
{
    return [
        'file' => 'image|video|mimes:jpeg,png,jpg,gif,svg,mp4,mov,avi,mkv',
    ];                   ^^^^^
}

There is no video validation rule (you can check the full list here). What you should do, instead, is make use of the mimes (or mimetypes) rule alone:

return [
    'file' => 'mimes:mp4,mov,avi,mkv',
];    

For the full list of mime extensions that you could use, here's the list.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...