CourseWork/app/Services/SubjectTeacherService.php
2024-05-06 17:47:25 +04:00

44 lines
994 B
PHP

<?php
namespace App\Services;
use App\Models\Subject;
use App\Models\Teacher;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class SubjectTeacherService implements ServiceInterface
{
public function getAll(Teacher $teacher = null): Collection
{
return $teacher->subjects;
}
public function getAllSubjects(): Collection
{
return Subject::all();
}
public function create(array $data, Model $model = null): Teacher
{
$model->subjects()->syncWithoutDetaching($data['subject_id']);
return $model;
}
public function update(Model $model, array $data, Model $subject = null): Teacher
{
$model->subjects()->detach($subject->id);
$model->subjects()->attach($data['subject_id']);
return $model;
}
public function delete(Model $model, Model $subject = null): Teacher
{
$model->subjects()->detach($subject);
return $model;
}
}