skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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!');
            
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search