siakad-itm/app/Http/Controllers/Admin/Users/LecturerController.php
Yoga Pangestu 2885de2c20 feat: add lecturer and student management pages with CRUD functionality
- Implemented LecturerEdit and LecturerIndex components for managing lecturers.
- Created StudentCreate and StudentEdit components for adding and editing students.
- Developed StudentIndex component for listing students with search and pagination.
- Added department and user types for better type safety.
- Updated routes for lecturers and students, including reset password functionality.
- Removed AppSidebar from dashboard for a cleaner layout.
2026-08-21 14:14:01 +07:00

79 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\Users;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Users\LecturerRequest;
use App\Models\User;
use App\Services\Admin\Users\DepartmentService;
use App\Services\Admin\Users\LecturerService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class LecturerController extends Controller
{
public function __construct(
protected LecturerService $service,
protected DepartmentService $departmentService,
) {}
public function index(Request $request): Response
{
return Inertia::render('admin/users/lecturers/index', [
'lecturers' => $this->service->getPaginated($request->only(['search', 'per_page'])),
'filters' => $request->only(['search', 'per_page']),
]);
}
public function create(): Response
{
return Inertia::render('admin/users/lecturers/create', [
'departments' => $this->departmentService->getAll(),
]);
}
public function store(LecturerRequest $request): RedirectResponse
{
$this->service->create($request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Dosen berhasil ditambahkan.']);
return to_route('admin.users.lecturers.index');
}
public function edit(User $user): Response
{
$user->load(['profile', 'lecturer.department']);
return Inertia::render('admin/users/lecturers/edit', [
'user' => $user,
'departments' => $this->departmentService->getAll(),
]);
}
public function update(LecturerRequest $request, User $user): RedirectResponse
{
$this->service->update($user, $request->validated());
Inertia::flash('toast', ['type' => 'success', 'message' => 'Dosen berhasil diperbarui.']);
return to_route('admin.users.lecturers.index');
}
public function destroy(User $user): RedirectResponse
{
$this->service->delete($user);
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Dosen berhasil dihapus.'])->back();
}
public function resetPassword(User $user): RedirectResponse
{
$this->service->resetPassword($user);
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Kata sandi berhasil direset.'])->back();
}
}