diff --git a/app/Helpers/PositionHelper.php b/app/Helpers/PositionHelper.php index 7e54a7f..8d5623e 100644 --- a/app/Helpers/PositionHelper.php +++ b/app/Helpers/PositionHelper.php @@ -3,6 +3,7 @@ namespace App\Helpers; use App\Models\Direction; +use App\Models\DirectionProfile; use App\Models\Faculty; use App\Models\EducationalInstitution; @@ -25,4 +26,10 @@ class PositionHelper $maxPosition = EducationalInstitution::max('position'); return $maxPosition >= 254 ? 255 : $maxPosition + 1; } + + public static function directionProfiles() + { + $maxPosition = DirectionProfile::max('position'); + return $maxPosition >= 254 ? 255 : $maxPosition + 1; + } } diff --git a/app/Http/Controllers/admin/Catalog/Direction/DirectionProfileController.php b/app/Http/Controllers/admin/Catalog/Direction/DirectionProfileController.php index c5ce09e..c4fd8d0 100644 --- a/app/Http/Controllers/admin/Catalog/Direction/DirectionProfileController.php +++ b/app/Http/Controllers/admin/Catalog/Direction/DirectionProfileController.php @@ -9,6 +9,9 @@ use App\Models\Direction; use App\Models\DirectionProfile; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Str; class DirectionProfileController extends Controller { @@ -28,13 +31,27 @@ class DirectionProfileController extends Controller { $validated = $request->validated(); + if ($validated['slug'] === null) { + $transliterationSlug = Str::slug($validated['name']); + $randomNumber = random_int(100, 999); + $slug = "{$transliterationSlug}-{$randomNumber}"; + } else { + $slug = $validated['slug']; + } + $directionProfile = new DirectionProfile(); $directionProfile->name = $validated['name']; $directionProfile->description = $validated['description']; - $directionProfile->slug = $validated['slug']; + $directionProfile->slug = $slug; $directionProfile->position = $validated['position']; $directionProfile->save(); + Log::channel('app') + ->info( + 'CREATE профиль подготовки {directionProfile} - user {user}', + ['user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $validated] + ); + return redirect()->route('direction_profiles.index'); } @@ -55,6 +72,7 @@ class DirectionProfileController extends Controller public function update(UpdateDirectionProfileRequest $request, DirectionProfile $directionProfile): RedirectResponse { $validated = $request->validated(); + $oldData = $directionProfile->toArray(); $directionProfile->name = $validated['name']; $directionProfile->description = $validated['description']; @@ -62,14 +80,43 @@ class DirectionProfileController extends Controller $directionProfile->position = $validated['position']; $directionProfile->save(); + Log::channel('app') + ->warning( + 'UPDATE профиль подготовки {directionProfile} - user {user}', + [ + 'user' => Auth::user()->name, + 'directionProfile' => $directionProfile->name, + 'oldData' => $oldData, + 'newData' => $validated + ] + ); + return redirect()->route('direction_profiles.index'); } public function destroy(DirectionProfile $directionProfile): RedirectResponse { if ($directionProfile->direction()->exists()) { + Log::channel('app') + ->error( + 'NOT DELETE профиль подготовки {directionProfile} - user {user}', + [ + 'user' => Auth::user()->name, + 'directionProfile' => $directionProfile->name, + 'data' => $directionProfile->toArray(), + ] + ); return back(); } + Log::channel('app') + ->critical( + 'DELETE профиль подготовки {directionProfile} - user {user}', + [ + 'user' => Auth::user()->name, + 'directionProfile' => $directionProfile->name, + 'data' => $directionProfile->toArray(), + ] + ); $directionProfile->delete(); return redirect()->route('direction_profiles.index'); } diff --git a/app/Http/Controllers/admin/Catalog/FacultyController.php b/app/Http/Controllers/admin/Catalog/FacultyController.php index 35b3764..69455b0 100644 --- a/app/Http/Controllers/admin/Catalog/FacultyController.php +++ b/app/Http/Controllers/admin/Catalog/FacultyController.php @@ -81,7 +81,7 @@ class FacultyController extends Controller $faculty->educational_institution_id = $validated['educational_institution_id']; Log::channel('app') - ->info( + ->warning( 'UPDATE факультет {faculty} - user {user}', [ 'user' => Auth::user()->name, @@ -97,15 +97,27 @@ class FacultyController extends Controller public function destroy(Faculty $faculty): RedirectResponse { - Log::channel('app') - ->info( - 'DELETE факультет {faculty} - user {user}', - ['user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $faculty->toArray()] - ); - if ($faculty->departments()->exists()) { + Log::channel('app') + ->critical( + 'NOT DELETE факультет {faculty} - user {user}', + [ + 'user' => Auth::user()->name, + 'faculty' => $faculty->name, + 'data' => $faculty->toArray(), + ] + ); return back(); } + Log::channel('app') + ->critical( + 'DELETE факультет {faculty} - user {user}', + [ + 'user' => Auth::user()->name, + 'faculty' => $faculty->name, + 'data' => $faculty->toArray(), + ] + ); $faculty->delete(); return redirect()->route('faculties.index'); } diff --git a/app/Http/Requests/admin/Catalog/Direction/StoreDirectionProfileRequest.php b/app/Http/Requests/admin/Catalog/Direction/StoreDirectionProfileRequest.php index 22bd567..17eb20e 100644 --- a/app/Http/Requests/admin/Catalog/Direction/StoreDirectionProfileRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/StoreDirectionProfileRequest.php @@ -15,9 +15,26 @@ class StoreDirectionProfileRequest extends FormRequest { return [ 'name' => 'required|string|max:255|unique:direction_profiles,name', - 'description' => 'string', - 'slug' => 'required|string|max:255|unique:direction_profiles,slug', + 'description' => 'nullable|string', + 'slug' => 'nullable|string|max:255|unique:direction_profiles,slug', 'position' => 'required|int|numeric|max:255', ]; } + + 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/UpdateDirectionProfileRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdateDirectionProfileRequest.php index 03ea02f..b82413f 100644 --- a/app/Http/Requests/admin/Catalog/Direction/UpdateDirectionProfileRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/UpdateDirectionProfileRequest.php @@ -14,10 +14,27 @@ class UpdateDirectionProfileRequest extends FormRequest public function rules(): array { return [ - 'name' => "required|string|max:255|unique:direction_profiles,name,{$this->direction_profile->id}", - 'description' => 'string', - 'slug' => "required|string|max:255|unique:direction_profiles,slug,{$this->direction_profile->id}", + 'name' => ['required', 'string', 'max:255', "unique:direction_profiles,name,{$this->direction_profile->id}",], + 'description' => 'nullable|string', + 'slug' => ['required', 'string', 'max:255', "unique:direction_profiles,slug,{$this->direction_profile->id}",], 'position' => 'required|int|numeric|max:255', ]; } + + 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/UpdateFacultyRequest.php b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php index 0484e83..42e10b9 100644 --- a/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateFacultyRequest.php @@ -16,7 +16,7 @@ class UpdateFacultyRequest extends FormRequest return [ 'position' => 'required|int|numeric|max:255', 'name' => ['required', 'string', 'max:255', "unique:faculties,name,{$this->faculty->id}",], - 'description' => 'string', + 'description' => 'nullable|string', 'slug' => ['required', 'string', 'max:255', "unique:faculties,slug,{$this->faculty->id}",], 'educational_institution_id' => 'required|int|numeric|max:1000', ]; diff --git a/lang/ru/tooltips.php b/lang/ru/tooltips.php index 530f8ab..89caa17 100644 --- a/lang/ru/tooltips.php +++ b/lang/ru/tooltips.php @@ -40,4 +40,10 @@ return [ 'description' => 'Поле "Описание" может быть пустым для отображения на сайте', 'slug' => 'Поле "URL" нужно для отображения в браузере' ], + 'direction_profiles' => [ + 'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте', + 'name' => 'Поле "Название" должно быть уникальным для отображения на сайте', + 'description' => 'Поле "Описание" может быть пустым для отображения на сайте', + 'slug' => 'Поле "URL" нужно для отображения в браузере' + ] ]; diff --git a/resources/views/admin/catalog/direction/direction_profile/create.blade.php b/resources/views/admin/catalog/direction/direction_profile/create.blade.php index 5a95909..c7e124c 100644 --- a/resources/views/admin/catalog/direction/direction_profile/create.blade.php +++ b/resources/views/admin/catalog/direction/direction_profile/create.blade.php @@ -1,59 +1,68 @@ +@php use App\Helpers\PositionHelper; @endphp @extends('layouts.admin_layout') @section('content') @auth()