CourseWork/app/Http/Controllers/GradeController.php
2024-05-06 17:47:25 +04:00

81 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\GradePostRequest;
use App\Models\Grade;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class GradeController extends Controller
{
public function __construct(
protected ServiceInterface $service,
){}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('grades.index', [
'grades' => $this->service->getAll(),
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('grades.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(GradePostRequest $request): RedirectResponse
{
return redirect()->route('grades.show', $this->service->create($request->validated()));
}
/**
* Display the specified resource.
*/
public function show(Grade $grade): View
{
return view('grades.show', [
'grade' => $grade,
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Grade $grade): View
{
return view('grades.edit', [
'grade' => $grade,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(GradePostRequest $request, Grade $grade): RedirectResponse
{
return redirect()->route('grades.show', $this->service->update($grade, $request->validated()));
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Grade $grade): RedirectResponse
{
$this->service->delete($grade);
return redirect()->route('grades.index');
}
}