CourseWork/app/Http/Controllers/GradeSubjectController.php

52 lines
1.5 KiB
PHP
Raw Permalink 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;
2024-06-24 22:04:44 +04:00
use App\Services\FileService;
2024-06-20 12:27:05 +04:00
use App\Services\JournalService;
2024-05-07 12:14:18 +04:00
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
}
2024-06-20 12:27:05 +04:00
public function destroy(Grade $grade, Subject $subject): RedirectResponse
2024-05-07 12:14:18 +04:00
{
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
}
2024-06-20 12:27:05 +04:00
public function journal(Grade $grade, Subject $subject, JournalService $service): View
2024-05-07 12:14:18 +04:00
{
2024-06-20 12:27:05 +04:00
return view('grade-subject.journal', [
'lessons' => $grade->lessons()->where('subject_id', $subject->id)->with('students')->get(),
'students' => $grade->students()->orderBy('last_name')->get(),
2024-06-24 22:04:44 +04:00
'grade' => $grade,
'subject' => $subject,
2024-06-20 12:27:05 +04:00
]);
2024-05-07 12:14:18 +04:00
}
2024-06-24 22:04:44 +04:00
public function exportToExcel(Grade $grade, Subject $subject, FileService $service)
{
return $service->exportJournal($grade, $subject);
}
2024-05-07 12:14:18 +04:00
}