$this->service->getAll(), ]); } public function create(): Response { return Inertia::render('admin/sdm/employee/create'); } public function store(EmployeeRequest $request): RedirectResponse { try { $this->service->create($request->validated()); Inertia::flash('toast', ['type' => 'success', 'message' => 'Pegawai berhasil ditambahkan.']); } catch (ValidationException $e) { $firstError = collect($e->errors())->flatten()->first(); Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']); } catch (\Exception $e) { Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]); } return to_route('admin.sdm.employees.index'); } public function edit(User $employee): Response { return Inertia::render('admin/sdm/employee/edit', [ 'employee' => $this->service->getById($employee->id), ]); } public function update(EmployeeRequest $request, User $employee): RedirectResponse { try { $this->service->update($employee, $request->validated()); Inertia::flash('toast', ['type' => 'success', 'message' => 'Pegawai berhasil diperbarui.']); } catch (ValidationException $e) { $firstError = collect($e->errors())->flatten()->first(); Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']); } catch (\Exception $e) { Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]); } return to_route('admin.sdm.employees.index'); } public function destroy(User $employee): RedirectResponse { try { $this->service->delete($employee); Inertia::flash('toast', ['type' => 'success', 'message' => 'Pegawai berhasil dihapus.']); } catch (ValidationException $e) { $firstError = collect($e->errors())->flatten()->first(); Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']); } catch (\Exception $e) { Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]); } return to_route('admin.sdm.employees.index'); } public function toggleActive(User $employee): RedirectResponse { try { $this->service->toggleActive($employee); $status = $employee->fresh()->is_active ? 'diaktifkan' : 'dinonaktifkan'; Inertia::flash('toast', ['type' => 'success', 'message' => "Pegawai berhasil {$status}."]); } catch (ValidationException $e) { $firstError = collect($e->errors())->flatten()->first(); Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']); } catch (\Exception $e) { Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]); } return to_route('admin.sdm.employees.index'); } public function resetPassword(User $employee): RedirectResponse { try { $this->service->resetPassword($employee); Inertia::flash('toast', ['type' => 'success', 'message' => 'Kata sandi pegawai berhasil direset ke kata sandi default.']); } catch (ValidationException $e) { $firstError = collect($e->errors())->flatten()->first(); Inertia::flash('toast', ['type' => 'error', 'message' => $firstError ?? 'Terjadi kesalahan.']); } catch (\Exception $e) { Inertia::flash('toast', ['type' => 'error', 'message' => $e->getMessage()]); } return to_route('admin.sdm.employees.index'); } }