CourseWork/app/Http/Controllers/LessonController.php
2024-05-08 16:55:32 +04:00

109 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Enums\TypeLesson;
use App\Http\Requests\LessonPostRequest;
use App\Models\Grade;
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,
){
}
public function gradeList(): View
{
return view('grade-lesson.grades-list', [
'grades' => $this->service->getGrades(),
]);
}
/**
* Display a listing of the resource.
*/
public function index(Grade $grade): View
{
return view('grade-lesson.index', [
'lessons' => $this->service->getAll($grade),
'grade' => $grade,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(Grade $grade): View
{
return view('grade-lesson.create', [
'types' => TypeLesson::cases(),
'grade' => $grade,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(LessonPostRequest $request, Grade $grade): RedirectResponse
{
return redirect()->route(
'grades.lessons.show', [
$grade,
$this->service->create($request->validated())
]
);
}
/**
* Display the specified resource.
*/
public function show(Grade $grade, Lesson $lesson): View
{
return view('grade-lesson.show', [
'lesson' => $lesson,
'grade' => $grade,
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Grade $grade, Lesson $lesson): View
{
return view('grade-lesson.edit', [
'lesson' => $lesson,
'grade' => $grade,
'types' => TypeLesson::cases(),
]);
}
/**
* Update the specified resource in storage.
*/
public function update(LessonPostRequest $request, Grade $grade, Lesson $lesson): RedirectResponse
{
return redirect()->route(
'grades.lessons.show',[
$grade,
$this->service->update($lesson, $request->validated())
]
);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Grade $grade, Lesson $lesson): RedirectResponse
{
$this->service->delete($lesson);
return redirect()->route('grades.lessons.index', $grade);
}
}