87 lines
1.9 KiB
PHP
87 lines
1.9 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 $teacherService
|
||
|
){}
|
||
|
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function index(): View
|
||
|
{
|
||
|
return view('teachers.index', [
|
||
|
'teachers' => $this->teacherService->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->teacherService->create($request->validated())
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Display the specified resource.
|
||
|
*/
|
||
|
public function show(Teacher $teacher): View
|
||
|
{
|
||
|
return view('teachers.show', [
|
||
|
'teacher' => $teacher,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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->teacherService->update($teacher, $request->validated())
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy(Teacher $teacher): RedirectResponse
|
||
|
{
|
||
|
$this->teacherService->delete($teacher);
|
||
|
|
||
|
return redirect()->route('teachers.index');
|
||
|
}
|
||
|
}
|