forked from aslan/applicant-site
prodV1 #2
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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 символов.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 символов.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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',
|
||||
];
|
||||
|
|
|
@ -40,4 +40,10 @@ return [
|
|||
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||
],
|
||||
'direction_profiles' => [
|
||||
'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте',
|
||||
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
|
||||
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||
]
|
||||
];
|
||||
|
|
|
@ -1,59 +1,68 @@
|
|||
@php use App\Helpers\PositionHelper; @endphp
|
||||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать Профиль Подготовки</h1>
|
||||
{{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
{{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ 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']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Позиция" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Название" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', '', ['class' => 'form-control']) }}
|
||||
{{ Form::text('description', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', '', ['class' => 'form-control']) }}
|
||||
{{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
|
|
|
@ -4,56 +4,65 @@
|
|||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="">Изменить Профиль Подготовки</h1>
|
||||
{{ 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']) }}
|
||||
<div class="col">
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ 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']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Позиция" обязательно!
|
||||
</div>
|
||||
<div>
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', $directionProfile->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Название" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ 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')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ 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')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', $directionProfile->position, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', '', ['class' => 'form-control']) }}
|
||||
{{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ 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')]) }}
|
||||
</div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
|
|
Loading…
Reference in New Issue