65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\SubjectTeacherPostRequest;
|
|
use App\Models\Subject;
|
|
use App\Models\Teacher;
|
|
use App\Services\ServiceInterface;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class SubjectTeacherController extends Controller
|
|
{
|
|
public function create(Teacher $teacher): View
|
|
{
|
|
return view('subject-teacher.create', [
|
|
'teacher' => $teacher,
|
|
'subjects' => Subject::all(),
|
|
]);
|
|
}
|
|
|
|
public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse
|
|
{
|
|
$teacher->subjects()->syncWithoutDetaching($request->subject_id);
|
|
|
|
return redirect()->route('teachers.show', $teacher);
|
|
}
|
|
|
|
public function show(Teacher $teacher, Subject $subject): View
|
|
{
|
|
return view('subject-teacher.show', [
|
|
'teacher' => $teacher,
|
|
'subject' => $subject,
|
|
'grades' => $teacher
|
|
->grades()
|
|
->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id')
|
|
->where('subject_id', $subject->id)->get(),
|
|
]);
|
|
}
|
|
|
|
public function edit(Teacher $teacher, Subject $subject): View
|
|
{
|
|
return view('subject-teacher.edit', [
|
|
'teacher' => $teacher,
|
|
'updateSubject' => $subject,
|
|
'subjects' => Subject::all(),
|
|
]);
|
|
}
|
|
|
|
public function update(SubjectTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse
|
|
{
|
|
$teacher->subjects()->detach($subject);
|
|
$teacher->subjects()->attach($request->subject_id);
|
|
|
|
return redirect()->route('teachers.show', $teacher);
|
|
}
|
|
|
|
public function destroy(Teacher $teacher, Subject $subject): RedirectResponse
|
|
{
|
|
$teacher->subjects()->detach($subject);
|
|
|
|
return redirect()->route('teachers.show', $teacher);
|
|
}
|
|
}
|