diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 8b858ff..3f487cc 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; class UserController extends Controller @@ -81,6 +82,11 @@ public function updateProfilePicture(Request $request) // Process the uploaded file and update the user's profile picture $user = Auth::user(); + // Hapus gambar lama jika ada + if ($user->profile_picture) { + Storage::disk('public')->delete($user->profile_picture); + } + // Store the uploaded file and update the user's profile picture if ($request->hasFile('profile_picture')) { $imagePath = $request->file('profile_picture')->store('profile_pictures', 'public');