siakad-itm/app/Services/Admin/Manage/CourseService.php
Yoga Pangestu a76ee85c24
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: add filter functionality to various admin pages
- Implemented filter dialogs in the following pages:
  - Academic Classes Assignments
  - Course Registrations
  - Materials
  - Announcements
  - Feedback
  - Tuition Invoices
  - Course Classes
  - Courses
  - Academic Terms
  - Academic Advising Logs
  - Letter Requests
  - Administrators
  - Lecturers
  - Students

- Updated the useServerTable hook to support filter parameters.
- Enhanced the UI with filter options for better data management and retrieval.
2026-08-26 00:32:16 +07:00

49 lines
1.5 KiB
PHP

<?php
namespace App\Services\Admin\Manage;
use App\Models\Course;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
class CourseService
{
public function getAllForSelect(): Collection
{
return Course::select(['id', 'code', 'name', 'department_id'])->get();
}
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', ?int $departmentId = null): LengthAwarePaginator
{
return Course::query()
->select(['id', 'code', 'name', 'credits', 'department_id', 'semester_number'])
->with('department:id,name')
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%")->orWhere('code', 'like', "%{$search}%"))
->when($departmentId, fn ($q) => $q->where('department_id', $departmentId))
->orderBy($sort, $direction)
->paginate($perPage);
}
public function create(array $data): Course
{
return Course::create($data);
}
public function update(Course $course, array $data): Course
{
$course->code = $data['code'];
$course->name = $data['name'];
$course->credits = $data['credits'];
$course->department_id = $data['department_id'];
$course->semester_number = $data['semester_number'] ?? null;
$course->update();
return $course;
}
public function delete(Course $course): bool
{
return $course->delete();
}
}