2024-02-14 15:00:28 +03:00
|
|
|
<?php
|
|
|
|
|
2024-02-16 09:06:48 +03:00
|
|
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
2024-02-14 15:00:28 +03:00
|
|
|
|
2024-03-12 15:32:18 +03:00
|
|
|
use App\Helpers\SlugHelper;
|
2024-02-14 15:00:28 +03:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-02-16 09:06:48 +03:00
|
|
|
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;
|
2024-03-12 15:32:18 +03:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-02-14 15:00:28 +03:00
|
|
|
|
|
|
|
class EducationLevelController extends Controller
|
|
|
|
{
|
|
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
$levels = EducationLevel::all();
|
2024-02-16 09:06:48 +03:00
|
|
|
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
|
|
|
|
{
|
2024-02-16 09:06:48 +03:00
|
|
|
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();
|
2024-03-12 15:32:18 +03:00
|
|
|
$slug = SlugHelper::get($validated);
|
|
|
|
|
2024-02-14 15:00:28 +03:00
|
|
|
$level = new EducationLevel();
|
|
|
|
$level->name = $validated['name'];
|
|
|
|
$level->description = $validated['description'];
|
2024-03-12 15:32:18 +03:00
|
|
|
$level->slug = $slug;
|
2024-02-14 15:00:28 +03:00
|
|
|
$level->save();
|
|
|
|
|
2024-03-12 15:32:18 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->info(
|
|
|
|
'CREATE уровень образования {educationLevel} - user {user}',
|
|
|
|
['user' => Auth::user()->name, 'educationLevel' => $level->name, 'data' => $validated]
|
|
|
|
);
|
|
|
|
|
2024-02-14 15:00:28 +03:00
|
|
|
return redirect()->route('education_levels.index');
|
|
|
|
}
|
|
|
|
|
2024-03-12 15:32:18 +03:00
|
|
|
public function show(EducationLevel $educationLevel): View
|
|
|
|
{
|
2024-02-14 15:00:28 +03:00
|
|
|
$directions = $educationLevel->directions();
|
|
|
|
return view(
|
2024-02-16 09:06:48 +03:00
|
|
|
'admin.catalog.direction.education_level.show',
|
2024-02-14 15:00:28 +03:00
|
|
|
compact('educationLevel', 'directions')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(EducationLevel $educationLevel)
|
|
|
|
{
|
2024-02-16 09:06:48 +03:00
|
|
|
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();
|
2024-03-12 15:32:18 +03:00
|
|
|
$oldData = $educationLevel->toArray();
|
2024-02-14 15:00:28 +03:00
|
|
|
|
|
|
|
$educationLevel->name = $validated['name'];
|
|
|
|
$educationLevel->description = $validated['description'];
|
|
|
|
$educationLevel->slug = $validated['slug'];
|
2024-03-12 15:32:18 +03:00
|
|
|
|
|
|
|
Log::channel('app')
|
|
|
|
->warning(
|
|
|
|
'UPDATE уровень образования {educationLevel} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationLevel' => $educationLevel->name,
|
|
|
|
'oldData' => $oldData,
|
|
|
|
'newData' => $validated
|
|
|
|
]
|
|
|
|
);
|
2024-02-14 15:00:28 +03:00
|
|
|
$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-03-12 15:32:18 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->error(
|
|
|
|
'NOT DELETE уровень образования {educationLevel} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationLevel' => $educationLevel->name,
|
|
|
|
'data' => $educationLevel->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-14 15:00:28 +03:00
|
|
|
return back();
|
|
|
|
}
|
2024-03-12 15:32:18 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->critical(
|
|
|
|
'DELETE уровень образования {educationLevel} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationLevel' => $educationLevel->name,
|
|
|
|
'data' => $educationLevel->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-14 15:00:28 +03:00
|
|
|
$educationLevel->delete();
|
|
|
|
return redirect()->route('education_levels.index');
|
|
|
|
}
|
|
|
|
}
|