itmpwk.ac.id/app/Http/Controllers/Admin/Master/DepartmentController.php
Yoga Pangestu 35a64c2045 feat: implement infinite scroll for various admin pages and update pagination handling
- Refactored AdministratorController, LecturerController, and StudentController to utilize Inertia's scroll feature for paginated data.
- Enhanced DataCards and DataTable components to support infinite scrolling, allowing for a smoother user experience when navigating large datasets.
- Updated multiple admin pages (e.g., MaterialIndex, LogIndex, FeedbackIndex) to integrate infinite scroll functionality, improving data loading efficiency.
- Adjusted server table hooks to reset keys appropriately for infinite scroll scenarios.
2026-09-04 13:59:26 +07:00

55 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Master;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Master\DepartmentRequest;
use App\Http\Requests\PaginatedRequest;
use App\Models\Department;
use App\Services\Admin\Master\DepartmentService;
use App\Services\Admin\Users\LecturerService;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;
class DepartmentController extends Controller
{
public function __construct(
private readonly DepartmentService $service,
private readonly LecturerService $lecturerService,
) {}
public function index(PaginatedRequest $request): Response
{
return Inertia::render('admin/master/departments/index', [
'departments' => Inertia::scroll(fn () => $this->service->paginated(...$request->validatedWithDefaults())),
'lecturers' => $this->lecturerService->getAllForSelect(),
]);
}
public function store(DepartmentRequest $request): RedirectResponse
{
$this->service->create($request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Jurusan berhasil ditambahkan.']);
return to_route('admin.master.departments.index');
}
public function update(DepartmentRequest $request, Department $department): RedirectResponse
{
$this->service->update($department, $request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Jurusan berhasil diperbarui.']);
return to_route('admin.master.departments.index');
}
public function destroy(Department $department): RedirectResponse
{
$this->service->delete($department);
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Jurusan berhasil dihapus.'])->back();
}
}