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