validate([ 'name' => 'required|string|max:255', 'username' => 'required|string|max:100', 'foto' => 'nullable|image|mimes:jpg,jpeg,png|max:2048', 'password' => 'nullable|min:6|confirmed', ]); // ====================== // UPDATE DATA DASAR // ====================== $admin->name = $request->name; $admin->username = $request->username; // ====================== // PROSES FOTO // ====================== if ($request->hasFile('foto')) { $path = public_path('assets/admin/foto-admin'); // buat folder kalau belum ada if (!File::exists($path)) { File::makeDirectory($path, 0755, true); } // hapus foto lama if ($admin->foto && File::exists($path.'/'.$admin->foto)) { File::delete($path.'/'.$admin->foto); } $file = $request->file('foto'); $namaFoto = time().'_'.uniqid().'.'.$file->getClientOriginalExtension(); // SIMPAN FOTO (INI KUNCI) $file->move($path, $namaFoto); // simpan ke DB $admin->foto = $namaFoto; } // ====================== // PASSWORD // ====================== if ($request->filled('password')) { $admin->password = Hash::make($request->password); } $admin->save(); return redirect() ->route('admin.profil') ->with('success', 'Profil berhasil diperbarui'); } }