119 lines
4.4 KiB
PHP
119 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin\Catalog;
|
|
|
|
use App\Helpers\SlugHelper;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\admin\Catalog\StoreEducationalInstitutionRequest;
|
|
use App\Http\Requests\admin\Catalog\UpdateEducationalInstitutionRequest;
|
|
use App\Models\EducationalInstitution;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class EducationalInstitutionController extends Controller
|
|
{
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
$educationalInstitutions = EducationalInstitution::all();
|
|
return view('admin.catalog.educational_institution.index', compact('educationalInstitutions'));
|
|
}
|
|
|
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
return view('admin.catalog.educational_institution.create');
|
|
}
|
|
|
|
public function store(StoreEducationalInstitutionRequest $request)
|
|
{
|
|
$validated = $request->validated();
|
|
|
|
$slug = SlugHelper::get($validated);
|
|
|
|
$educationalInstitution = new EducationalInstitution();
|
|
$educationalInstitution->name = $validated['name'];
|
|
$educationalInstitution->description = $validated['description'];
|
|
$educationalInstitution->slug = $slug;
|
|
$educationalInstitution->position = $validated['position'];
|
|
$educationalInstitution->save();
|
|
|
|
Log::channel('app')
|
|
->info(
|
|
'CREATE учеб. заведение {educationalInstitution} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
'data' => $validated
|
|
]
|
|
);
|
|
|
|
return redirect()->route('educational_institutions.index');
|
|
}
|
|
|
|
public function show(EducationalInstitution $educationalInstitution)
|
|
{
|
|
return view('admin.catalog.educational_institution.show', compact('educationalInstitution'));
|
|
}
|
|
|
|
public function edit(EducationalInstitution $educationalInstitution)
|
|
{
|
|
return view('admin.catalog.educational_institution.edit', compact('educationalInstitution'));
|
|
}
|
|
|
|
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
|
|
{
|
|
$validated = $request->validated();
|
|
$oldData = $educationalInstitution->toArray();
|
|
|
|
$educationalInstitution->name = $validated['name'];
|
|
$educationalInstitution->description = $validated['description'];
|
|
$educationalInstitution->position = $validated['position'];
|
|
$educationalInstitution->slug = $validated['slug'];
|
|
|
|
Log::channel('app')
|
|
->warning(
|
|
'UPDATE учеб. заведение {educationalInstitution} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'faculty' => $educationalInstitution->name,
|
|
'oldData' => $oldData,
|
|
'newData' => $validated
|
|
]
|
|
);
|
|
|
|
$educationalInstitution->save();
|
|
|
|
return redirect()->route('educational_institutions.index');
|
|
}
|
|
|
|
public function destroy(EducationalInstitution $educationalInstitution)
|
|
{
|
|
if ($educationalInstitution->faculties()->exists()) {
|
|
Log::channel('app')
|
|
->error(
|
|
'NOT DELETE учеб. заведение {educationalInstitution} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
'data' => $educationalInstitution->toArray(),
|
|
]
|
|
);
|
|
return back();
|
|
}
|
|
Log::channel('app')
|
|
->critical(
|
|
'DELETE учеб. заведение {educationalInstitution} - user {user}',
|
|
[
|
|
'user' => Auth::user()->name,
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
'data' => $educationalInstitution->toArray(),
|
|
]
|
|
);
|
|
$educationalInstitution->delete();
|
|
|
|
return redirect()->route('educational_institutions.index');
|
|
}
|
|
}
|