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

75 lines
2.5 KiB
PHP
Raw Normal View History

2024-02-14 15:00:28 +03:00
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
2024-02-14 15:00:28 +03:00
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreEducationLevelRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateEducationLevelRequest;
2024-02-14 15:00:28 +03:00
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.direction.education_level.index', compact('levels'));
2024-02-14 15:00:28 +03:00
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
return view('admin.catalog.direction.education_level.create');
2024-02-14 15:00:28 +03:00
}
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
2024-02-14 16:41:51 +03:00
): View|Application|Factory|\Illuminate\Contracts\Foundation\Application {
2024-02-14 15:00:28 +03:00
$directions = $educationLevel->directions();
return view(
'admin.catalog.direction.education_level.show',
2024-02-14 15:00:28 +03:00
compact('educationLevel', 'directions')
);
}
public function edit(EducationLevel $educationLevel)
{
return view('admin.catalog.direction.education_level.edit', compact('educationLevel'));
2024-02-14 15:00:28 +03:00
}
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)
{
2024-02-14 16:41:51 +03:00
if ($educationLevel->directions()->exists()) {
2024-02-14 15:00:28 +03:00
return back();
}
$educationLevel->delete();
return redirect()->route('education_levels.index');
}
}