48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Eloquent;
|
|
|
|
use App\Models\CourseSchedule;
|
|
use App\Repositories\Contracts\ScheduleRepositoryInterface;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/**
|
|
* @extends BaseRepository<CourseSchedule>
|
|
*/
|
|
class ScheduleRepository extends BaseRepository implements ScheduleRepositoryInterface
|
|
{
|
|
public function __construct(CourseSchedule $model)
|
|
{
|
|
parent::__construct($model);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $filters
|
|
* @return LengthAwarePaginator<int, CourseSchedule>
|
|
*/
|
|
public function paginate(array $filters = [], int $perPage = 15): LengthAwarePaginator
|
|
{
|
|
$query = $this->model->newQuery()->with('course.category');
|
|
|
|
if (! empty($filters['course_id'])) {
|
|
$query->where('course_id', $filters['course_id']);
|
|
}
|
|
|
|
return $query->orderBy('start_date')->paginate($perPage);
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, CourseSchedule>
|
|
*/
|
|
public function upcoming(int $limit = 20): Collection
|
|
{
|
|
return $this->model->newQuery()
|
|
->with('course.category')
|
|
->where('start_date', '>=', now())
|
|
->orderBy('start_date')
|
|
->limit($limit)
|
|
->get();
|
|
}
|
|
}
|