115 lines
4.0 KiB
PHP
115 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
|
|
|
use App\Helpers\SlugHelper;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\admin\Catalog\Direction\StoreEducationLevelRequest;
|
|
use App\Http\Requests\admin\Catalog\Direction\UpdateEducationLevelRequest;
|
|
use App\Models\EducationLevel;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
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'));
|
|
}
|
|
|
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
return view('admin.catalog.direction.education_level.create');
|
|
}
|
|
|
|
public function store(StoreEducationLevelRequest $request): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
$slug = SlugHelper::get($validated);
|
|
|
|
$level = new EducationLevel();
|
|
$level->name = $validated['name'];
|
|
$level->description = $validated['description'];
|
|
$level->slug = $slug;
|
|
$level->save();
|
|
|
|
Log::channel('app')
|
|
->info(
|
|
'CREATE уровень образования {educationLevel} - user {user}',
|
|
['user' => Auth::user()->name, 'educationLevel' => $level->name, 'data' => $validated]
|
|
);
|
|
|
|
return redirect()->route('education_levels.index');
|
|
}
|
|
|
|
public function show(EducationLevel $educationLevel): View
|
|
{
|
|
$directions = $educationLevel->directions();
|
|
return view(
|
|
'admin.catalog.direction.education_level.show',
|
|
compact('educationLevel', 'directions')
|
|
);
|
|
}
|
|
|
|
public function edit(EducationLevel $educationLevel)
|
|
{
|
|
return view('admin.catalog.direction.education_level.edit', compact('educationLevel'));
|
|
}
|
|
|
|
public function update(UpdateEducationLevelRequest $request, EducationLevel $educationLevel): RedirectResponse
|
|
{
|
|
$validated = $request->validated();
|
|
$oldData = $educationLevel->toArray();
|
|
|
|
$educationLevel->name = $validated['name'];
|
|
$educationLevel->description = $validated['description'];
|
|
$educationLevel->slug = $validated['slug'];
|
|
|
|
Log::channel('app')
|
|
->warning(
|
|
'UPDATE уровень образования {educationLevel} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationLevel' => $educationLevel->name,
|
|
'oldData' => $oldData,
|
|
'newData' => $validated
|
|
]
|
|
);
|
|
$educationLevel->save();
|
|
|
|
return redirect()->route('education_levels.index');
|
|
}
|
|
|
|
public function destroy(EducationLevel $educationLevel)
|
|
{
|
|
if ($educationLevel->directions()->exists()) {
|
|
Log::channel('app')
|
|
->error(
|
|
'NOT DELETE уровень образования {educationLevel} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationLevel' => $educationLevel->name,
|
|
'data' => $educationLevel->toArray(),
|
|
]
|
|
);
|
|
return back();
|
|
}
|
|
Log::channel('app')
|
|
->critical(
|
|
'DELETE уровень образования {educationLevel} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationLevel' => $educationLevel->name,
|
|
'data' => $educationLevel->toArray(),
|
|
]
|
|
);
|
|
$educationLevel->delete();
|
|
return redirect()->route('education_levels.index');
|
|
}
|
|
}
|