52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\GradeSubjectPostRequest;
|
|
use App\Models\Grade;
|
|
use App\Models\Subject;
|
|
use App\Services\ServiceInterface;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\View\View;
|
|
|
|
class GradeSubjectController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ServiceInterface $service,
|
|
) {
|
|
}
|
|
|
|
public function create(Grade $grade): View
|
|
{
|
|
return view('grade-subject.create', [
|
|
'grade' => $grade,
|
|
'subjects' => $this->service->getAllSubjects(),
|
|
]);
|
|
}
|
|
|
|
public function store(GradeSubjectPostRequest $request, Grade $grade): RedirectResponse
|
|
{
|
|
return redirect()->route('grades.show', $this->service->create($request->validated(), $grade));
|
|
}
|
|
|
|
public function edit(Grade $grade, Subject $subject): View
|
|
{
|
|
return view('grade-subject.edit', [
|
|
'grade' => $grade,
|
|
'updateSubject' => $subject,
|
|
'subjects' => $this->service->getAllSubjects(),
|
|
]);
|
|
}
|
|
|
|
public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse
|
|
{
|
|
return redirect()->route('grades.show',
|
|
$this->service->update($grade, $request->validated(), $subject));
|
|
}
|
|
|
|
public function destroy(Grade $grade, Subject $subject): RedirectResponse
|
|
{
|
|
return redirect()->route('grades.show', $this->service->delete($grade, $subject));
|
|
}
|
|
}
|