'menu-profile', ]; return view('profil.setting', [ 'user' => $request->user(), ], $data); } // Halaman edit profile public function edit() { $data = [ 'active' => 'menu-profile', ]; return view('profil.profil', $data); } //Proses update Profile public function updateprofile(Request $request, $id) { $request->validate([ 'fullname' => 'required', 'email' => 'required', 'no_hp' => 'required', 'foto' => 'image|mimes:jpeg,png,jpg,gif|max:2048', // Validasi jenis file gambar 'tgl_lahir' => 'required', 'jenis_kelamin' => 'required', 'agama' => 'required', 'address' => 'required', ]); try { $pengguna = User::findOrFail($id); // Handle foto upload if provided if ($request->hasFile('foto')) { // Hapus foto lama jika ada if ($pengguna->foto) { Storage::delete('public/' . $pengguna->foto); } $randomFileName = Str::random(20); // Menghasilkan nama file acak dengan panjang 20 karakter $fotoPath = $request->file('foto')->storeAs('public/Profile_foto', $randomFileName); $pengguna->foto = str_replace('public/', '', $fotoPath); } // Update other fields $pengguna->fullname = $request->fullname; $pengguna->email = $request->email; $pengguna->no_hp = $request->no_hp; $pengguna->tgl_lahir = $request->tgl_lahir; $pengguna->jenis_kelamin = $request->jenis_kelamin; $pengguna->agama = $request->agama; $pengguna->address = $request->address; $pengguna->save(); return redirect()->back()->with('success', 'Profil pengguna berhasil diperbarui'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data pengguna gagal diubah'); } } //Proses update Profile Informasi // public function update(ProfileUpdateRequest $request): RedirectResponse // { // $request->user()->fill($request->validated()); // if ($request->user()->isDirty('email')) { // $request->user()->email_verified_at = null; // } // $request->user()->save(); // return Redirect::back()->with('status', 'profile-updated'); // } public function update(ProfileUpdateRequest $request): RedirectResponse { try { $request->user()->fill($request->validated()); if ($request->user()->isDirty('email')) { $request->user()->email_verified_at = null; } $request->user()->save(); return Redirect::back()->with('success', 'Akun berhasil diupdate.'); } catch (\Exception $e) { return Redirect::back()->with('error', 'Gagal mengupdate akun. Silakan coba lagi.'); } } }