user(); return view('siswa.profile.edit', compact('siswa')); } public function update(Request $request) { $siswa = Auth::guard('siswa')->user(); $request->validate([ 'password' => 'nullable|min:6|confirmed', 'password_confirmation' => 'nullable', 'foto_profil' => 'nullable|image|mimes:jpg,jpeg,png,webp|max:2048', ], [ 'password.min' => 'Password minimal 6 karakter.', 'password.confirmed' => 'Konfirmasi password tidak cocok.', 'foto_profil.image' => 'File harus berupa gambar.', 'foto_profil.max' => 'Ukuran foto maksimal 2MB.', ]); $data = []; // Update password if ($request->filled('password')) { $data['password'] = Hash::make($request->password); } // Update foto profil if ($request->hasFile('foto_profil')) { // Hapus foto lama jika ada if ($siswa->foto_profil && Storage::disk('public')->exists($siswa->foto_profil)) { Storage::disk('public')->delete($siswa->foto_profil); } $path = $request->file('foto_profil')->store('foto_profil/siswa', 'public'); $data['foto_profil'] = $path; } if (!empty($data)) { $siswa->update($data); } return redirect()->route('siswa.profile.edit') ->with('success', 'Profil berhasil diperbarui!'); } }