61 lines
1.8 KiB
PHP
61 lines
1.8 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 __construct(
|
|
protected ServiceInterface $service,
|
|
) {
|
|
}
|
|
|
|
public function create(Teacher $teacher): View
|
|
{
|
|
return view('subject-teacher.create', [
|
|
'teacher' => $teacher,
|
|
'subjects' => $this->service->getAllSubjects(),
|
|
]);
|
|
}
|
|
|
|
public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse
|
|
{
|
|
return redirect()->route('teachers.show', $this->service->create($request->validated(), $teacher));
|
|
}
|
|
|
|
public function show(Teacher $teacher, Subject $subject): View
|
|
{
|
|
return view('subject-teacher.show', [
|
|
'teacher' => $teacher,
|
|
'subject' => $subject,
|
|
'grades' => $this->service->getGrades($teacher, $subject),
|
|
]);
|
|
}
|
|
|
|
public function edit(Teacher $teacher, Subject $subject): View
|
|
{
|
|
return view('subject-teacher.edit', [
|
|
'teacher' => $teacher,
|
|
'updateSubject' => $subject,
|
|
'subjects' => $this->service->getAllSubjects(),
|
|
]);
|
|
}
|
|
|
|
public function update(SubjectTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse
|
|
{
|
|
return redirect()->route('teachers.show',
|
|
$this->service->update($teacher, $request->validated(), $subject));
|
|
}
|
|
|
|
public function destroy(Teacher $teacher, Subject $subject): RedirectResponse
|
|
{
|
|
return redirect()->route('teachers.show', $this->service->delete($teacher, $subject));
|
|
}
|
|
}
|