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