CourseWork/app/Http/Controllers/GradeSubjectController.php

53 lines
1.4 KiB
PHP
Raw Normal View History

2024-05-07 12:14:18 +04:00
<?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,
2024-06-16 00:41:31 +04:00
'subjects' => Subject::all(),
2024-05-07 12:14:18 +04:00
]);
}
public function store(GradeSubjectPostRequest $request, Grade $grade): RedirectResponse
{
2024-06-16 00:41:31 +04:00
$grade->subjects()->syncWithoutDetaching($request->subject_id);
2024-06-16 12:20:48 +04:00
return redirect()->route('grades.show', $grade);
2024-05-07 12:14:18 +04:00
}
public function edit(Grade $grade, Subject $subject): View
{
return view('grade-subject.edit', [
'grade' => $grade,
'updateSubject' => $subject,
2024-06-16 00:41:31 +04:00
'subjects' => Subject::all(),
2024-05-07 12:14:18 +04:00
]);
}
public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse
{
2024-06-16 12:20:48 +04:00
$grade->subjects()->detach($subject);
$grade->subjects()->attach($request->subject_id);
return redirect()->route('grades.show', $grade);
2024-05-07 12:14:18 +04:00
}
public function destroy(Grade $grade, Subject $subject): RedirectResponse
{
2024-06-16 12:20:48 +04:00
$grade->subjects()->detach($subject);
return redirect()->route('grades.show', $grade);
2024-05-07 12:14:18 +04:00
}
}