54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Manage\Service;
|
|
|
|
use App\Models\AcademicAdvisingLog;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
class AcademicAdvisingLogService
|
|
{
|
|
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator
|
|
{
|
|
return AcademicAdvisingLog::query()
|
|
->select(['id', 'student_id', 'lecturer_id', 'topic', 'notes', 'session_date', 'created_at'])
|
|
->with([
|
|
'student.user.profile',
|
|
'student.department',
|
|
'lecturer.user.profile',
|
|
])
|
|
->when($search, fn ($q) => $q->where('topic', 'like', "%{$search}%")
|
|
->orWhereHas('student', fn ($q) => $q->where('student_number', 'like', "%{$search}%")
|
|
->orWhereHas('user.profile', fn ($q) => $q->where('full_name', 'like', "%{$search}%"))))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function create(array $data): AcademicAdvisingLog
|
|
{
|
|
return AcademicAdvisingLog::create([
|
|
'student_id' => $data['student_id'],
|
|
'lecturer_id' => $data['lecturer_id'],
|
|
'topic' => $data['topic'] ?? null,
|
|
'notes' => $data['notes'] ?? null,
|
|
'session_date' => $data['session_date'] ?? now(),
|
|
]);
|
|
}
|
|
|
|
public function update(AcademicAdvisingLog $log, array $data): AcademicAdvisingLog
|
|
{
|
|
$log->student_id = $data['student_id'];
|
|
$log->lecturer_id = $data['lecturer_id'];
|
|
$log->topic = $data['topic'] ?? null;
|
|
$log->notes = $data['notes'] ?? null;
|
|
$log->session_date = $data['session_date'] ?? now();
|
|
$log->update();
|
|
|
|
return $log;
|
|
}
|
|
|
|
public function delete(AcademicAdvisingLog $log): bool
|
|
{
|
|
return $log->delete();
|
|
}
|
|
}
|