diff --git a/app/Helpers/PositionHelper.php b/app/Helpers/PositionHelper.php index 448875e..906f875 100644 --- a/app/Helpers/PositionHelper.php +++ b/app/Helpers/PositionHelper.php @@ -4,6 +4,7 @@ namespace App\Helpers; use App\Models\Direction; use App\Models\DirectionProfile; +use App\Models\ExaminationType; use App\Models\Faculty; use App\Models\EducationalInstitution; use App\Models\SubjectType; @@ -46,4 +47,10 @@ class PositionHelper $maxPosition = Subject::max('position'); return $maxPosition >= 254 ? 255 : $maxPosition + 1; } + + public static function examinationType() + { + $maxPosition = ExaminationType::max('position'); + return $maxPosition >= 254 ? 255 : $maxPosition + 1; + } } diff --git a/app/Http/Controllers/admin/Catalog/Direction/ExaminationTypeController.php b/app/Http/Controllers/admin/Catalog/Direction/ExaminationTypeController.php index 1bf134b..db98788 100644 --- a/app/Http/Controllers/admin/Catalog/Direction/ExaminationTypeController.php +++ b/app/Http/Controllers/admin/Catalog/Direction/ExaminationTypeController.php @@ -2,12 +2,15 @@ namespace App\Http\Controllers\admin\Catalog\Direction; +use App\Helpers\SlugHelper; use App\Http\Controllers\Controller; use App\Http\Requests\admin\Catalog\Direction\StoreExaminationTypeRequest; use App\Http\Requests\admin\Catalog\Direction\UpdateExaminationTypeRequest; use App\Models\ExaminationType; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; class ExaminationTypeController extends Controller { @@ -26,13 +29,21 @@ class ExaminationTypeController extends Controller { $validated = $request->validated(); + $slug = SlugHelper::get($validated); + $type = new ExaminationType(); $type->name = $validated['name']; $type->description = $validated['description']; - $type->slug = $validated['slug']; + $type->slug = $slug; $type->position = $validated['position']; $type->save(); + Log::channel('app') + ->info( + 'CREATE тип экзамена {examinationType} - user {user}', + ['user' => Auth::user()->name, 'faculty' => $type->name, 'data' => $validated] + ); + return redirect()->route('examination_types.index'); } @@ -49,21 +60,52 @@ class ExaminationTypeController extends Controller public function update(UpdateExaminationTypeRequest $request, ExaminationType $examinationType): RedirectResponse { $validated = $request->validated(); + $oldData = $examinationType->toArray(); $examinationType->name = $validated['name']; $examinationType->description = $validated['description']; $examinationType->slug = $validated['slug']; $examinationType->position = $validated['position']; - $examinationType->save(); + Log::channel('app') + ->warning( + 'UPDATE тип экзамена {examinationType} - user {user}', + [ + 'user' => Auth::user()->name, + 'examinationType' => $examinationType->name, + 'oldData' => $oldData, + 'newData' => $validated + ] + ); + + $examinationType->save(); return redirect()->route('examination_types.index'); } public function destroy(ExaminationType $examinationType): RedirectResponse { if ($examinationType->entranceExaminations()->exists()) { + Log::channel('app') + ->error( + 'NOT DELETE тип экзамена {examinationType} - user {user}', + [ + 'user' => Auth::user()->name, + 'examinationType' => $examinationType->name, + 'data' => $examinationType->toArray(), + ] + ); return back(); } + + Log::channel('app') + ->critical( + 'DELETE тип экзамена {examinationType} - user {user}', + [ + 'user' => Auth::user()->name, + 'examinationType' => $examinationType->name, + 'data' => $examinationType->toArray(), + ] + ); $examinationType->delete(); return redirect()->route('examination_types.index'); } diff --git a/app/Http/Requests/admin/Catalog/Direction/StoreExaminationTypeRequest.php b/app/Http/Requests/admin/Catalog/Direction/StoreExaminationTypeRequest.php index a094703..a05abfd 100644 --- a/app/Http/Requests/admin/Catalog/Direction/StoreExaminationTypeRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/StoreExaminationTypeRequest.php @@ -16,8 +16,24 @@ class StoreExaminationTypeRequest extends FormRequest return [ 'position' => 'required|int|numeric|max:255', 'name' => 'required|string|max:255|unique:examination_types,name', - 'description' => 'string', - 'slug' => 'required|string|max:255|unique:examination_types,slug', + 'description' => 'nullable|string', + 'slug' => 'nullable|string|max:255|unique:examination_types,slug', + ]; + } + public function messages(): array + { + return [ + 'position.required' => 'Поле позиция обязательно.', + 'position.int' => 'Позиция должно быть целым числом.', + 'position.numeric' => 'Позиция должно быть числом.', + 'position.max' => 'Позиция не должен быть больше :max', + 'name.required' => 'Поле название обязательно.', + 'name.string' => 'Поле название должен быть строкой.', + 'name.max' => 'Поле название не должен превышать :max символов.', + 'name.unique' => 'Название уже занят.', + 'description.string' => 'Поле описание должен быть строкой.', + 'slug.string' => 'Поле URL должен быть строкой.', + 'slug.max' => 'Поле URL не должен превышать :max символов.', ]; } } diff --git a/app/Http/Requests/admin/Catalog/Direction/UpdateExaminationTypeRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdateExaminationTypeRequest.php index 9f96463..d772aba 100644 --- a/app/Http/Requests/admin/Catalog/Direction/UpdateExaminationTypeRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/UpdateExaminationTypeRequest.php @@ -15,7 +15,7 @@ class UpdateExaminationTypeRequest extends FormRequest { return [ 'position' => 'required|int|numeric|max:255', - 'description' => 'string', + 'description' => 'nullable|string', 'slug' => [ 'string', 'required', @@ -30,4 +30,21 @@ class UpdateExaminationTypeRequest extends FormRequest ], ]; } + + public function messages(): array + { + return [ + 'position.required' => 'Поле позиция обязательно.', + 'position.int' => 'Позиция должно быть целым числом.', + 'position.numeric' => 'Позиция должно быть числом.', + 'position.max' => 'Позиция не должен быть больше :max', + 'name.required' => 'Поле название обязательно.', + 'name.string' => 'Поле название должен быть строкой.', + 'name.max' => 'Поле название не должен превышать :max символов.', + 'name.unique' => 'Название уже занят.', + 'description.string' => 'Поле описание должен быть строкой.', + 'slug.string' => 'Поле URL должен быть строкой.', + 'slug.max' => 'Поле URL не должен превышать :max символов.', + ]; + } } diff --git a/lang/ru/tooltips.php b/lang/ru/tooltips.php index 7250373..e66ef29 100644 --- a/lang/ru/tooltips.php +++ b/lang/ru/tooltips.php @@ -58,4 +58,10 @@ return [ 'description' => 'Поле "Описание" может быть пустым для отображения на сайте', 'slug' => 'Поле "URL" нужно для отображения в браузере' ], + 'examination_types' => [ + 'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте', + 'name' => 'Поле "Название" должно быть уникальным для отображения на сайте', + 'description' => 'Поле "Описание" может быть пустым для отображения на сайте', + 'slug' => 'Поле "URL" нужно для отображения в браузере' + ], ]; diff --git a/resources/views/admin/catalog/direction/examination_type/create.blade.php b/resources/views/admin/catalog/direction/examination_type/create.blade.php index 1d6cef9..565808d 100644 --- a/resources/views/admin/catalog/direction/examination_type/create.blade.php +++ b/resources/views/admin/catalog/direction/examination_type/create.blade.php @@ -1,59 +1,69 @@ +@php use App\Helpers\PositionHelper; @endphp @extends('layouts.admin_layout') @section('content') @auth()