icelander
1 month ago
427
8
Laravel

how to upload a video file into my database in laravel

Posted 1 month ago by icelander

hi. please how do I upload a video or powerpoint or image to my table in my database. but after what I have done I got this error message

The slide must be a file of type: mp4, ppx, pdf, ogv, jpg, webm. 
 public function doupload(Request $request){

    	$this->validate($request,[
            'subject'=> 'required',
            'class'=> 'required',
            'topic'=> 'required',
            'slide'=> 'required|mimes:mp4,ppx,pdf,ogv,jpg,webm|max:1999',
             

        ]);

       $name= Auth::guard('teacher')->user()->name;
       return $name;
        if($request->hasFile('slide')){
            $filenameWithExt= $request->file('slide')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extension = $request->file('slide')->getClientOriginalExtension();
            $fileNameToStore = $filename. '_'.time().'.'.$extension;
            $path = $request->file('slide')->storeAs('public/videos/',$fileNameToStore);
        }else{
            $fileNameToStore = 'noimage.jpg';
        }
         $slide = new Slide;
        $slide->topic = $request->input('topic');
         $slide->subject = $request->input('subject');
         $slide->class = $request->input('class');
         $slidefile = $fileNameToStore;
         $slide->teacher = $request->input('teacher');
         $slide->save();

        return back()->with('success', ' Upload Successfull');
    }

Please sign in or create an account to participate in this conversation.