CourseWork/app/Services/LessonService.php

46 lines
948 B
PHP
Raw Normal View History

2024-05-08 12:59:29 +04:00
<?php
namespace App\Services;
2024-05-27 16:57:28 +04:00
use App\Enums\ScoreEnum;
2024-05-08 16:55:32 +04:00
use App\Models\Grade;
2024-05-08 12:59:29 +04:00
use App\Models\Lesson;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class LessonService implements ServiceInterface
{
2024-05-08 16:55:32 +04:00
public function getAll(?Grade $grade = null): Collection
2024-05-08 12:59:29 +04:00
{
2024-05-13 14:23:21 +04:00
return $grade->lessons()->filter()->get();
2024-05-08 16:55:32 +04:00
}
public function getGrades(): Collection
{
return Grade::all();
2024-05-08 12:59:29 +04:00
}
public function create(array $data): Lesson
{
2024-05-27 16:57:28 +04:00
$lesson = Lesson::create($data);
$lesson
->students()
->syncWithPivotValues($lesson->grade->students->pluck('id')->all(), ['score' => ScoreEnum::WithoutScore]);
return $lesson;
2024-05-08 12:59:29 +04:00
}
public function update(Model $model, array $data): Lesson
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->delete();
}
}