2024-02-07 10:18:46 +03:00
|
|
|
<?php
|
|
|
|
|
2024-02-12 14:55:17 +03:00
|
|
|
namespace App\Http\Controllers\admin\Catalog;
|
2024-02-07 10:18:46 +03:00
|
|
|
|
2024-03-13 11:28:12 +03:00
|
|
|
use App\Helpers\SlugHelper;
|
2024-02-08 16:01:40 +03:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-02-12 14:55:17 +03:00
|
|
|
use App\Http\Requests\admin\Catalog\StoreEducationalInstitutionRequest;
|
|
|
|
use App\Http\Requests\admin\Catalog\UpdateEducationalInstitutionRequest;
|
2024-02-07 10:18:46 +03:00
|
|
|
use App\Models\EducationalInstitution;
|
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Foundation\Application;
|
2024-03-13 11:24:10 +03:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2024-02-07 10:18:46 +03:00
|
|
|
|
|
|
|
class EducationalInstitutionController extends Controller
|
|
|
|
{
|
|
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
$educationalInstitutions = EducationalInstitution::all();
|
2024-02-12 14:55:17 +03:00
|
|
|
return view('admin.catalog.educational_institution.index', compact('educationalInstitutions'));
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
2024-02-12 14:55:17 +03:00
|
|
|
return view('admin.catalog.educational_institution.create');
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(StoreEducationalInstitutionRequest $request)
|
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
2024-03-13 11:28:12 +03:00
|
|
|
$slug = SlugHelper::get($validated);
|
|
|
|
|
2024-02-07 10:18:46 +03:00
|
|
|
$educationalInstitution = new EducationalInstitution();
|
|
|
|
$educationalInstitution->name = $validated['name'];
|
|
|
|
$educationalInstitution->description = $validated['description'];
|
2024-03-13 11:28:12 +03:00
|
|
|
$educationalInstitution->slug = $slug;
|
2024-02-07 10:18:46 +03:00
|
|
|
$educationalInstitution->position = $validated['position'];
|
|
|
|
$educationalInstitution->save();
|
|
|
|
|
2024-03-13 11:24:10 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->info(
|
|
|
|
'CREATE учеб. заведение {educationalInstitution} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
|
|
'data' => $validated
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-02-12 14:55:17 +03:00
|
|
|
return redirect()->route('educational_institutions.index');
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function show(EducationalInstitution $educationalInstitution)
|
|
|
|
{
|
2024-02-12 14:55:17 +03:00
|
|
|
return view('admin.catalog.educational_institution.show', compact('educationalInstitution'));
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(EducationalInstitution $educationalInstitution)
|
|
|
|
{
|
2024-02-12 14:55:17 +03:00
|
|
|
return view('admin.catalog.educational_institution.edit', compact('educationalInstitution'));
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
|
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
2024-03-13 11:24:10 +03:00
|
|
|
$oldData = $educationalInstitution->toArray();
|
2024-02-07 10:18:46 +03:00
|
|
|
|
|
|
|
$educationalInstitution->name = $validated['name'];
|
|
|
|
$educationalInstitution->description = $validated['description'];
|
|
|
|
$educationalInstitution->position = $validated['position'];
|
2024-02-12 14:55:17 +03:00
|
|
|
$educationalInstitution->slug = $validated['slug'];
|
2024-03-13 11:24:10 +03:00
|
|
|
|
|
|
|
Log::channel('app')
|
|
|
|
->warning(
|
|
|
|
'UPDATE учеб. заведение {educationalInstitution} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'faculty' => $educationalInstitution->name,
|
|
|
|
'oldData' => $oldData,
|
|
|
|
'newData' => $validated
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2024-02-07 10:18:46 +03:00
|
|
|
$educationalInstitution->save();
|
|
|
|
|
2024-02-12 14:55:17 +03:00
|
|
|
return redirect()->route('educational_institutions.index');
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(EducationalInstitution $educationalInstitution)
|
|
|
|
{
|
2024-02-07 16:34:04 +03:00
|
|
|
if ($educationalInstitution->faculties()->exists()) {
|
2024-03-13 11:24:10 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->error(
|
|
|
|
'NOT DELETE учеб. заведение {educationalInstitution} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
|
|
'data' => $educationalInstitution->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-07 16:34:04 +03:00
|
|
|
return back();
|
|
|
|
}
|
2024-03-13 11:24:10 +03:00
|
|
|
Log::channel('app')
|
|
|
|
->critical(
|
|
|
|
'DELETE учеб. заведение {educationalInstitution} - user {user}',
|
|
|
|
[
|
|
|
|
'user' => Auth::user()->name,
|
|
|
|
'educationalInstitution' => $educationalInstitution->name,
|
|
|
|
'data' => $educationalInstitution->toArray(),
|
|
|
|
]
|
|
|
|
);
|
2024-02-07 10:18:46 +03:00
|
|
|
$educationalInstitution->delete();
|
|
|
|
|
2024-02-12 14:55:17 +03:00
|
|
|
return redirect()->route('educational_institutions.index');
|
2024-02-07 10:18:46 +03:00
|
|
|
}
|
|
|
|
}
|