Preview dan Delete Profile Picture

This commit is contained in:
Ananda Zakia S 2023-12-28 00:06:03 +07:00
parent 326bbfd7ac
commit 97c9669a82
1 changed files with 6 additions and 0 deletions

View File

@ -7,6 +7,7 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
class UserController extends Controller class UserController extends Controller
@ -81,6 +82,11 @@ public function updateProfilePicture(Request $request)
// Process the uploaded file and update the user's profile picture // Process the uploaded file and update the user's profile picture
$user = Auth::user(); $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 // Store the uploaded file and update the user's profile picture
if ($request->hasFile('profile_picture')) { if ($request->hasFile('profile_picture')) {
$imagePath = $request->file('profile_picture')->store('profile_pictures', 'public'); $imagePath = $request->file('profile_picture')->store('profile_pictures', 'public');