app/Http/Controllers/Admin/VideoController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $request->validate([
            'title' => 'required|max:250',
            'category' => 'required',
            'details' => 'required',
            'image' => 'nullable|image',
            'file' => 'nullable|file',
            'video_id' => 'required|max:1000',
            'duration' => 'required|max:10',
            'tags' => 'required',
        ]);
        if($request->hasFile('image')){
            $old_file = Video::find($id);
            $file_path = public_path('uploads/'.$this->url.'/thumb/'.$old_file->image_path);
            if(File::isFile($file_path)){
                File::delete($file_path);
            }
            $filenameWithExt = $request->file('image')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); 
            $extension = $request->file('image')->getClientOriginalExtension();
            $thumbNameToStore = $filename.'_'.time().'.'.$extension;
            $path = public_path('uploads/'.$this->url.'/thumb/');
            if (! File::exists($path)) {
                File::makeDirectory($path, 0777, true, true);
            }
            $thumbnailpath = $path.$thumbNameToStore;
            $img = Image::make($request->file('image')->getRealPath())->fit(250, 140, function ($constraint) { $constraint->upsize(); })->save($thumbnailpath);
        }
        else{
            $old_file = Video::find($id);
            $thumbNameToStore = $old_file->image_path; 
        }
        if($request->hasFile('file')){
            $old_file = Video::find($id);
            $file_path = public_path('uploads/'.$this->url.'/'.$old_file->video_path);
            if(File::isFile($file_path)){
                File::delete($file_path);
            }
            $filenameWithExt = $request->file('file')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME); 
            $extension = $request->file('file')->getClientOriginalExtension();
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            $path = public_path('uploads/'.$this->url.'/');
            if (! File::exists($path)) {
                File::makeDirectory($path, 0777, true, true);
            }
            $file = $request->file('file')->move($path, $fileNameToStore);
        }
        else{
            $old_file = Video::find($id);
            $fileNameToStore = $old_file->video_path; 
        }
        if(empty($request->featured)){ $request->featured = 0; }
        if(empty($request->quality)){ $request->quality = 0; }
        $data = Video::find($id);
        $data->title = $request->title;
        $data->category_id = $request->category;
        $data->description = $request->details;
        $data->image_path = $thumbNameToStore;
        $data->video_type = $request->video_type;
        $data->video_path = $fileNameToStore;
        $data->video_id = $request->video_id;
        $data->duration = $request->duration;
        $data->featured = $request->featured;
        $data->quality = $request->quality;
        $data->status = $request->status;
        $data->updated_by = Auth::user()->id;
        $data->save();
        $data->tags()->sync($request->tags);
        Toastr::success($this->title.' Updated Successfully!', 'success');
        return redirect()->back();
    }
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'title' => 'required|max:250' , 'category' => 'required' , 'details' => 'required' , 'image' => 'nullable|image' , 'file' => 'nullable|file' , 'video_id' => 'required|max:1000' , 'duration' => 'required|max:10' , 'tags' => 'required' , ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ old_file = Video :: find ( $ id ) ; $ file_path = public_path ( 'uploads/' . $ this -> url . '/thumb/' . $ old_file -> image_path ) ; if ( File :: isFile ( $ file_path ) ) { File :: delete ( $ file_path ) ; } $ filenameWithExt = $ request -> file ( 'image' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'image' ) -> getClientOriginalExtension ( ) ; $ thumbNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = public_path ( 'uploads/' . $ this -> url . '/thumb/' ) ; if ( ! File :: exists ( $ path ) ) { File :: makeDirectory ( $ path , 0777 , true , true ) ; } $ thumbnailpath = $ path . $ thumbNameToStore ; $ img = Image :: make ( $ request -> file ( 'image' ) -> getRealPath ( ) ) -> fit ( 250 , 140 , function ( $ constraint ) { $ constraint -> upsize ( ) ; } ) -> save ( $ thumbnailpath ) ; } else { $ old_file = Video :: find ( $ id ) ; $ thumbNameToStore = $ old_file -> image_path ; } if ( $ request -> hasFile ( 'file' ) ) { $ old_file = Video :: find ( $ id ) ; $ file_path = public_path ( 'uploads/' . $ this -> url . '/' . $ old_file -> video_path ) ; if ( File :: isFile ( $ file_path ) ) { File :: delete ( $ file_path ) ; } $ filenameWithExt = $ request -> file ( 'file' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'file' ) -> getClientOriginalExtension ( ) ; $ fileNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = public_path ( 'uploads/' . $ this -> url . '/' ) ; if ( ! File :: exists ( $ path ) ) { File :: makeDirectory ( $ path , 0777 , true , true ) ; } $ file = $ request -> file ( 'file' ) -> move ( $ path , $ fileNameToStore ) ; } else { $ old_file = Video :: find ( $ id ) ; $ fileNameToStore = $ old_file -> video_path ; } if ( empty ( $ request -> featured ) ) { $ request -> featured = 0 ; } if ( empty ( $ request -> quality ) ) { $ request -> quality = 0 ; } $ data = Video :: find ( $ id ) ; $ data -> title = $ request -> title ; $ data -> category_id = $ request -> category ; $ data -> description = $ request -> details ; $ data -> image_path = $ thumbNameToStore ; $ data -> video_type = $ request -> video_type ; $ data -> video_path = $ fileNameToStore ; $ data -> video_id = $ request -> video_id ; $ data -> duration = $ request -> duration ; $ data -> featured = $ request -> featured ; $ data -> quality = $ request -> quality ; $ data -> status = $ request -> status ; $ data -> updated_by = Auth :: user ( ) -> id ; $ data -> save ( ) ; $ data -> tags ( ) -> sync ( $ request -> tags ) ; Toastr :: success ( $ this -> title . ' Updated Successfully!' , 'success' ) ; return redirect ( ) -> back ( ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// Field Validation // image upload, fit and store inside public folder  //Delete Old Image //Upload New Image //Crete Folder Location //Resize And Crop as Fit image here (250 width, 140 height) // file upload, fit and store inside public folder  //Delete Old Image //Upload New Image //Crete Folder Location // Move File inside public/uploads/ folder // Update Data // Update Tags