Home > front end >  Method Illuminate\Validation\Validator::validateVideo does not exist. Can't fix
Method Illuminate\Validation\Validator::validateVideo does not exist. Can't fix

Time:11-04

I get this error after submitting the form. Here's the controller code.

The error appears to be in the validate() part.


    public function store(Request $request) {
        $video = new Video();
        $request->validate([
            'title' => 'required|max:68',
            'description' => 'required|max:256',
            'image' => 'image|mimes:jpeg,png,jpg,webp|max:2048',
            'video' => 'video|mimes:m4v,avi,flv,mp4,mov',
        ]);
    
        if($request->image) {           
            $title = uniqid().'.'.$request->image->extension();
            $request->image->move(public_path('video/images'), $title);
            $video->image = $title;         
        }  
    
        if($request->video) {           
            $title = uniqid().'.'.$request->video->extension();
            $request->video->move(public_path('video/videos'), $title);
            $video->video = $title;         
        } 
    
        $video->title = $request->title;        
        $video->description = $request->description;        
        $video->save();
    
        return redirect()->route('videos.list')->with('Success','video created successfully!');
        
    }

Thanks in advance

I tried different things but I still need figuring this out

CodePudding user response:

Change

'video' => 'video|mimes:m4v,avi,flv,mp4,mov',

to

'video' => 'mimetypes:video/m4v,video/avi,video/flv,video/mp4,video/mov',

Docs: https://laravel.com/docs/9.x/validation#rule-mimetypes

CodePudding user response:

laravel doesn't support video attribute

Would use this version


  public function store(Request $request) {
        $video = new Video();
        $request->validate([
            'title' => 'required|max:68',
            'description' => 'required|max:256',
            'image' => 'image|mimes:jpeg,png,jpg,webp|max:2048',
            'video' => 'mimes:m4v,avi,flv,mp4,mov',
        ]);
    
        if($request->image) {           
            $title = uniqid().'.'.$request->image->extension();
            $request->image->move(public_path('video/images'), $title);
            $video->image = $title;         
        }  
    
        if($request->video) {           
            $title = uniqid().'.'.$request->video->extension();
            $request->video->move(public_path('video/videos'), $title);
            $video->video = $title;         
        } 
    
        $video->title = $request->title;        
        $video->description = $request->description;        
        $video->save();
    
        return redirect()->route('videos.list')->with('Success','video created successfully!');
        
    }
  • Related