app/Http/Controllers/Admin/categoryController.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)
    {
        if($request->image!=null){
            $categories=categories::where('slug',$id)->first();
            $image = $request->image;
            $imgName=Str::slug($request->name).uniqid().'.'. $image->getClientOriginalExtension();
            if(!Storage::disk('public')->exists('category')){
                Storage::disk('public')->makeDirectory('category');
            }
            $image->storeAs('category',$imgName,'public');
            if(Storage::disk('public')->exists('category/'.$categories->image)){
                unlink('storage/category/'.$categories->image);
            }
            $categories->name=$request->name;
            $categories->slug= Str::slug($request->name) ;
            $categories->disc=$request->disc;
            $categories->image=$imgName;
            $categories->save();
        }else{
            $categories=categories::where('slug',$id)->first();
            $categories->name=$request->name;
            $categories->slug= Str::slug($request->name) ;
            $categories->disc=$request->disc;
            $categories->save();
        }
        Toastr::success('Successfully', 'Category Updated',["progressBar" => true,"timeOut"=> "1200",]) ;
        return redirect()->route('admin.category.index');
    }
public function update ( Request $ request , $ id ) { if ( $ request -> image != null ) { $ categories = categories :: where ( 'slug' , $ id ) -> first ( ) ; $ image = $ request -> image ; $ imgName = Str :: slug ( $ request -> name ) . uniqid ( ) . '.' . $ image -> getClientOriginalExtension ( ) ; if ( ! Storage :: disk ( 'public' ) -> exists ( 'category' ) ) { Storage :: disk ( 'public' ) -> makeDirectory ( 'category' ) ; } $ image -> storeAs ( 'category' , $ imgName , 'public' ) ; if ( Storage :: disk ( 'public' ) -> exists ( 'category/' . $ categories -> image ) ) { unlink ( 'storage/category/' . $ categories -> image ) ; } $ categories -> name = $ request -> name ; $ categories -> slug = Str :: slug ( $ request -> name ) ; $ categories -> disc = $ request -> disc ; $ categories -> image = $ imgName ; $ categories -> save ( ) ; } else { $ categories = categories :: where ( 'slug' , $ id ) -> first ( ) ; $ categories -> name = $ request -> name ; $ categories -> slug = Str :: slug ( $ request -> name ) ; $ categories -> disc = $ request -> disc ; $ categories -> save ( ) ; } Toastr :: success ( 'Successfully' , 'Category Updated' , [ " progressBar " => true , " timeOut " => " 1200 " , ] ) ; return redirect ( ) -> route ( 'admin.category.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// check image exists or not in folder