applicant-site/app/Http/Controllers/admin/Catalog/EducationLevelController.php

75 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\admin\Catalog;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\StoreEducationLevelRequest;
use App\Http\Requests\admin\Catalog\UpdateEducationLevelRequest;
use App\Models\EducationLevel;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
class EducationLevelController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$levels = EducationLevel::all();
return view('admin.catalog.education_level.index', compact('levels'));
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
return view('admin.catalog.education_level.create');
}
public function store(StoreEducationLevelRequest $request): RedirectResponse
{
$validated = $request->validated();
$level = new EducationLevel();
$level->name = $validated['name'];
$level->description = $validated['description'];
$level->slug = $validated['slug'];
$level->save();
return redirect()->route('education_levels.index');
}
public function show(
EducationLevel $educationLevel
): View|Application|Factory|\Illuminate\Contracts\Foundation\Application {
$directions = $educationLevel->directions();
return view(
'admin.catalog.education_level.show',
compact('educationLevel', 'directions')
);
}
public function edit(EducationLevel $educationLevel)
{
return view('admin.catalog.education_level.edit', compact('educationLevel'));
}
public function update(UpdateEducationLevelRequest $request, EducationLevel $educationLevel): RedirectResponse
{
$validated = $request->validated();
$educationLevel->name = $validated['name'];
$educationLevel->description = $validated['description'];
$educationLevel->slug = $validated['slug'];
$educationLevel->save();
return redirect()->route('education_levels.index');
}
public function destroy(EducationLevel $educationLevel)
{
if ($educationLevel->directions()->exists()) {
return back();
}
$educationLevel->delete();
return redirect()->route('education_levels.index');
}
}