CourseWork/app/Http/Controllers/LessonController.php
2024-05-08 12:59:29 +04:00

89 lines
1.9 KiB
PHP

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