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()

Создать Профиль Подготовки

- {{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => '']) }} + {{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
- {{ Form::label('name', 'Название') }} + {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }} + *
- {{ Form::text('name', '', ['class' => 'form-control']) }} + {{ Form::text('position', PositionHelper::faculty(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position'), 'required']) }} +
+ Поле "Позиция" обязательно! +
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }} + * +
+
+ {{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }} +
+ Поле "Название" обязательно! +
+
+
@if ($errors->any()) {{ $errors->first('name') }} @endif
- {{ Form::label('description', 'Описание') }} + {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
- {{ Form::text('description', '', ['class' => 'form-control']) }} + {{ Form::text('description', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
-
+
@if ($errors->any()) {{ $errors->first('description') }} @endif
- {{ Form::label('slug', 'URL') }} + {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
- {{ Form::text('slug', '', ['class' => 'form-control']) }} + {{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
-
+
@if ($errors->any()) {{ $errors->first('slug') }} @endif
-
- {{ Form::label('position', 'Позиция') }} -
-
- {{ Form::text('position', '', ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('position') }} - @endif -
-
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/admin/catalog/direction/direction_profile/edit.blade.php b/resources/views/admin/catalog/direction/direction_profile/edit.blade.php index caf84b0..e08e77d 100644 --- a/resources/views/admin/catalog/direction/direction_profile/edit.blade.php +++ b/resources/views/admin/catalog/direction/direction_profile/edit.blade.php @@ -4,56 +4,65 @@

Изменить Профиль Подготовки

- {{ Form::open(['url' => route('direction_profiles.update', $directionProfile), 'method' => 'PATCH', 'class' => '']) }} + {{ Form::open(['url' => route('direction_profiles.update', $directionProfile), 'method' => 'PATCH', 'class' => 'needs-validation', 'novalidate']) }}
+
- {{ Form::label('name', 'Название') }} + {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }} + *
- {{ Form::text('name', $directionProfile->name, ['class' => 'form-control']) }} + {{ Form::text('position', $directionProfile->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position'), 'required']) }} +
+ Поле "Позиция" обязательно! +
-
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }} + * +
+
+ {{ Form::text('name', $directionProfile->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }} +
+ Поле "Название" обязательно! +
+
+
@if ($errors->any()) {{ $errors->first('name') }} @endif
- {{ Form::label('description', 'Описание') }} + {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
- {{ Form::text('description', $directionProfile->description, ['class' => 'form-control']) }} + {{ Form::text('description', $directionProfile->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
-
+
@if ($errors->any()) {{ $errors->first('description') }} @endif
- {{ Form::label('slug', 'URL') }} + {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
- {{ Form::text('slug', $directionProfile->slug, ['class' => 'form-control']) }} + {{ Form::text('slug', $directionProfile->slug, ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
-
+
@if ($errors->any()) {{ $errors->first('slug') }} @endif
-
- {{ Form::label('position', 'Позиция') }} -
-
- {{ Form::text('position', $directionProfile->position, ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('position') }} - @endif -
-
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/admin/catalog/educational_institution/create.blade.php b/resources/views/admin/catalog/educational_institution/create.blade.php index 2e45e91..0d6b372 100644 --- a/resources/views/admin/catalog/educational_institution/create.blade.php +++ b/resources/views/admin/catalog/educational_institution/create.blade.php @@ -54,7 +54,7 @@ {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
- {{ Form::text('slug', '', ['class' => 'form-control']) }} + {{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
@if ($errors->any()) diff --git a/resources/views/admin/catalog/faculty/create.blade.php b/resources/views/admin/catalog/faculty/create.blade.php index 2ec995b..4d9dd5a 100644 --- a/resources/views/admin/catalog/faculty/create.blade.php +++ b/resources/views/admin/catalog/faculty/create.blade.php @@ -66,7 +66,7 @@ {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
- {{ Form::text('slug', '', ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }} + {{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
@if ($errors->any())