CourseWork/app/Services/LessonService.php
m.zargarov 92efb4498d Fixed
2024-05-27 16:57:28 +04:00

46 lines
948 B
PHP

<?php
namespace App\Services;
use App\Enums\ScoreEnum;
use App\Models\Grade;
use App\Models\Lesson;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class LessonService implements ServiceInterface
{
public function getAll(?Grade $grade = null): Collection
{
return $grade->lessons()->filter()->get();
}
public function getGrades(): Collection
{
return Grade::all();
}
public function create(array $data): Lesson
{
$lesson = Lesson::create($data);
$lesson
->students()
->syncWithPivotValues($lesson->grade->students->pluck('id')->all(), ['score' => ScoreEnum::WithoutScore]);
return $lesson;
}
public function update(Model $model, array $data): Lesson
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->delete();
}
}