CourseWork/app/Http/Controllers/LessonController.php

110 lines
2.6 KiB
PHP
Raw Normal View History

2024-05-08 12:59:29 +04:00
<?php
namespace App\Http\Controllers;
2024-05-08 13:34:54 +04:00
use App\Enums\TypeLesson;
2024-05-08 12:59:29 +04:00
use App\Http\Requests\LessonPostRequest;
2024-05-08 16:55:32 +04:00
use App\Models\Grade;
2024-05-08 12:59:29 +04:00
use App\Models\Lesson;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class LessonController extends Controller
{
public function __construct
(
protected ServiceInterface $service,
){
}
2024-05-08 16:55:32 +04:00
public function gradeList(): View
{
return view('grade-lesson.grades-list', [
'grades' => $this->service->getGrades(),
]);
}
2024-05-08 12:59:29 +04:00
/**
* Display a listing of the resource.
*/
2024-05-08 16:55:32 +04:00
public function index(Grade $grade): View
2024-05-08 12:59:29 +04:00
{
2024-05-08 16:55:32 +04:00
return view('grade-lesson.index', [
'lessons' => $this->service->getAll($grade),
'grade' => $grade,
2024-05-13 14:23:21 +04:00
'subjects' => $grade->subjects,
2024-05-08 12:59:29 +04:00
]);
}
/**
* Show the form for creating a new resource.
*/
2024-05-08 16:55:32 +04:00
public function create(Grade $grade): View
2024-05-08 12:59:29 +04:00
{
2024-05-08 16:55:32 +04:00
return view('grade-lesson.create', [
2024-05-08 13:34:54 +04:00
'types' => TypeLesson::cases(),
2024-05-08 16:55:32 +04:00
'grade' => $grade,
2024-05-08 13:34:54 +04:00
]);
2024-05-08 12:59:29 +04:00
}
/**
* Store a newly created resource in storage.
*/
2024-05-08 16:55:32 +04:00
public function store(LessonPostRequest $request, Grade $grade): RedirectResponse
2024-05-08 12:59:29 +04:00
{
return redirect()->route(
2024-05-08 16:55:32 +04:00
'grades.lessons.show', [
$grade,
$this->service->create($request->validated())
]
2024-05-08 12:59:29 +04:00
);
}
/**
* Display the specified resource.
*/
2024-05-08 16:55:32 +04:00
public function show(Grade $grade, Lesson $lesson): View
2024-05-08 12:59:29 +04:00
{
2024-05-08 16:55:32 +04:00
return view('grade-lesson.show', [
2024-05-08 12:59:29 +04:00
'lesson' => $lesson,
2024-05-08 16:55:32 +04:00
'grade' => $grade,
2024-05-08 12:59:29 +04:00
]);
}
/**
* Show the form for editing the specified resource.
*/
2024-05-08 16:55:32 +04:00
public function edit(Grade $grade, Lesson $lesson): View
2024-05-08 12:59:29 +04:00
{
2024-05-08 16:55:32 +04:00
return view('grade-lesson.edit', [
2024-05-08 12:59:29 +04:00
'lesson' => $lesson,
2024-05-08 16:55:32 +04:00
'grade' => $grade,
2024-05-08 13:34:54 +04:00
'types' => TypeLesson::cases(),
2024-05-08 12:59:29 +04:00
]);
}
/**
* Update the specified resource in storage.
*/
2024-05-08 16:55:32 +04:00
public function update(LessonPostRequest $request, Grade $grade, Lesson $lesson): RedirectResponse
2024-05-08 12:59:29 +04:00
{
return redirect()->route(
2024-05-08 16:55:32 +04:00
'grades.lessons.show',[
$grade,
$this->service->update($lesson, $request->validated())
]
2024-05-08 12:59:29 +04:00
);
}
/**
* Remove the specified resource from storage.
*/
2024-05-08 16:55:32 +04:00
public function destroy(Grade $grade, Lesson $lesson): RedirectResponse
2024-05-08 12:59:29 +04:00
{
$this->service->delete($lesson);
2024-05-08 16:55:32 +04:00
return redirect()->route('grades.lessons.index', $grade);
2024-05-08 12:59:29 +04:00
}
}