Home > Software engineering >  How to delete image from storage in restfull api
How to delete image from storage in restfull api

Time:01-29

  $employee = Employee::find($id);
        Storage::delete($employee->photo_file_path . $employee->photo_file_type);
        $file = $request->image;
        $path = $file->storeAs('public/images', $id . '.' . $file->getClientOriginalExtension());
        $employee->photo_file_name = $id;
        $employee->photo_file_type = $file->getClientOriginalExtension();
        $employee->photo_file_path = $path;

when uploading photos, I want the previous photo to be deleted first and then insert a new photo again, I use Storage::delete. I have checked the public folder but the previous photo was not deleted, instead the photo was added

CodePudding user response:

If you are uploading images in public folder then you need to add public before your path

Storage::delete('public/'.$employee->photo_file_path . $employee->photo_file_type);

CodePudding user response:

if(file_exists(public_path('upload/bio.png'))){unlink(public_path('upload/bio.png')); }else{dd('File does not exists.');}

  •  Tags:  
  • Related