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

44 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\GradeSubjectPostRequest;
use App\Models\Grade;
use App\Models\Subject;
use App\Services\JournalService;
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 destroy(Grade $grade, Subject $subject): RedirectResponse
{
$grade->subjects()->detach($subject);
return redirect()->route('grades.show', $grade);
}
public function journal(Grade $grade, Subject $subject, JournalService $service): View
{
return view('grade-subject.journal', [
'lessons' => $grade->lessons()->where('subject_id', $subject->id)->with('students')->get(),
'students' => $grade->students()->orderBy('last_name')->get(),
]);
}
}