siakad-itm/app/Services/Admin/Manage/Course/CourseService.php
Yoga Pangestu 353829e053
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: Refactor Admin Manage structure into sub-namespaces for better organization
- Created sub-namespaces under Admin\Manage for Course, Academic, Announcement, Finance, and Service.
- Added new FormRequest classes for handling validation in each sub-namespace.
- Implemented Service classes for managing business logic related to each resource.
- Updated routes to reflect the new sub-namespace structure.
- Enhanced code organization and maintainability by grouping related functionalities.
2026-08-25 21:17:48 +07:00

48 lines
1.4 KiB
PHP

<?php
namespace App\Services\Admin\Manage\Course;
use App\Models\Course;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Collection;
class CourseService
{
public function getAll(): 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', array $filters = []): 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}%"))
->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();
}
}