CourseWork/app/Http/Controllers/GradeTeacherController.php

64 lines
1.7 KiB
PHP
Raw Normal View History

2024-05-07 15:05:10 +04:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\GradeTeacherPostRequest;
use App\Models\Grade;
use App\Models\Subject;
use App\Models\Teacher;
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,
2024-06-16 12:20:48 +04:00
'grades' => $subject->grades,
2024-05-07 15:05:10 +04:00
]);
}
public function store(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse
{
2024-06-16 12:20:48 +04:00
$teacher->grades()->syncWithoutDetaching($request->grade_id);
2024-05-07 15:05:10 +04:00
return redirect()->route('teachers.subjects.show', [
2024-06-16 12:20:48 +04:00
$teacher,
2024-05-07 15:05:10 +04:00
$subject,
]);
}
public function edit(Teacher $teacher, Subject $subject, Grade $grade): View
{
return view('grade-teacher.edit', [
'teacher' => $teacher,
'subject' => $subject,
'updateGrade' => $grade,
2024-06-16 12:20:48 +04:00
'grades' => $subject->grades,
2024-05-07 15:05:10 +04:00
]);
}
public function update(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse
{
2024-06-16 12:20:48 +04:00
$teacher->grades()->detach($grade);
$teacher->grades()->attach($request->grade_id);
2024-05-07 15:05:10 +04:00
return redirect()->route('teachers.subjects.show', [
2024-06-16 12:20:48 +04:00
$teacher,
2024-05-07 15:05:10 +04:00
$subject,
]);
}
public function destroy(Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse
{
2024-06-16 12:20:48 +04:00
$teacher->grades()->detach($grade);
2024-05-07 15:05:10 +04:00
return redirect()->route('teachers.subjects.show', [
2024-06-16 12:20:48 +04:00
$teacher,
2024-05-07 15:05:10 +04:00
$subject,
]);
}
}