Reputation: 375
$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
Upvotes: 0
Views: 159
Reputation: 138
if(file_exists(public_path('upload/bio.png'))){unlink(public_path('upload/bio.png')); }else{dd('File does not exists.');}
Upvotes: 0
Reputation: 198
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);
Upvotes: 1