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

87 lines
1.9 KiB
PHP

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