CourseWork/app/Http/Controllers/GradeTeacherController.php
2024-06-16 12:20:48 +04:00

65 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\GradeTeacherPostRequest;
use App\Models\Grade;
use App\Models\Subject;
use App\Models\Teacher;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class GradeTeacherController extends Controller
{
public function create(Teacher $teacher, Subject $subject): View
{
return view('grade-teacher.create', [
'teacher' => $teacher,
'subject' => $subject,
'grades' => $subject->grades,
]);
}
public function store(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse
{
$teacher->grades()->syncWithoutDetaching($request->grade_id);
return redirect()->route('teachers.subjects.show', [
$teacher,
$subject,
]);
}
public function edit(Teacher $teacher, Subject $subject, Grade $grade): View
{
return view('grade-teacher.edit', [
'teacher' => $teacher,
'subject' => $subject,
'updateGrade' => $grade,
'grades' => $subject->grades,
]);
}
public function update(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse
{
$teacher->grades()->detach($grade);
$teacher->grades()->attach($request->grade_id);
return redirect()->route('teachers.subjects.show', [
$teacher,
$subject,
]);
}
public function destroy(Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse
{
$teacher->grades()->detach($grade);
return redirect()->route('teachers.subjects.show', [
$teacher,
$subject,
]);
}
}