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

53 lines
1.4 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 create(Grade $grade): View
{
return view('grade-subject.create', [
'grade' => $grade,
'subjects' => Subject::all(),
]);
}
public function store(GradeSubjectPostRequest $request, Grade $grade): RedirectResponse
{
$grade->subjects()->syncWithoutDetaching($request->subject_id);
return redirect()->route('grades.show', $grade);
}
public function edit(Grade $grade, Subject $subject): View
{
return view('grade-subject.edit', [
'grade' => $grade,
'updateSubject' => $subject,
'subjects' => Subject::all(),
]);
}
public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse
{
$grade->subjects()->detach($subject);
$grade->subjects()->attach($request->subject_id);
return redirect()->route('grades.show', $grade);
}
public function destroy(Grade $grade, Subject $subject): RedirectResponse
{
$grade->subjects()->detach($subject);
return redirect()->route('grades.show', $grade);
}
}