prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
6 changed files with 105 additions and 26 deletions
Showing only changes of commit 299817069e - Show all commits

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Helpers\SlugHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreEducationLevelRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateEducationLevelRequest;
@ -10,6 +11,8 @@ use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
class EducationLevelController extends Controller
{
@ -27,18 +30,25 @@ class EducationLevelController extends Controller
public function store(StoreEducationLevelRequest $request): RedirectResponse
{
$validated = $request->validated();
$slug = SlugHelper::get($validated);
$level = new EducationLevel();
$level->name = $validated['name'];
$level->description = $validated['description'];
$level->slug = $validated['slug'];
$level->slug = $slug;
$level->save();
Log::channel('app')
->info(
'CREATE уровень образования {educationLevel} - user {user}',
['user' => Auth::user()->name, 'educationLevel' => $level->name, 'data' => $validated]
);
return redirect()->route('education_levels.index');
}
public function show(
EducationLevel $educationLevel
): View|Application|Factory|\Illuminate\Contracts\Foundation\Application {
public function show(EducationLevel $educationLevel): View
{
$directions = $educationLevel->directions();
return view(
'admin.catalog.direction.education_level.show',
@ -54,10 +64,22 @@ class EducationLevelController extends Controller
public function update(UpdateEducationLevelRequest $request, EducationLevel $educationLevel): RedirectResponse
{
$validated = $request->validated();
$oldData = $educationLevel->toArray();
$educationLevel->name = $validated['name'];
$educationLevel->description = $validated['description'];
$educationLevel->slug = $validated['slug'];
Log::channel('app')
->warning(
'UPDATE уровень образования {educationLevel} - user {user}',
[
'user' => Auth::user()->name,
'educationLevel' => $educationLevel->name,
'oldData' => $oldData,
'newData' => $validated
]
);
$educationLevel->save();
return redirect()->route('education_levels.index');
@ -66,8 +88,26 @@ class EducationLevelController extends Controller
public function destroy(EducationLevel $educationLevel)
{
if ($educationLevel->directions()->exists()) {
Log::channel('app')
->error(
'NOT DELETE уровень образования {educationLevel} - user {user}',
[
'user' => Auth::user()->name,
'educationLevel' => $educationLevel->name,
'data' => $educationLevel->toArray(),
]
);
return back();
}
Log::channel('app')
->critical(
'DELETE уровень образования {educationLevel} - user {user}',
[
'user' => Auth::user()->name,
'educationLevel' => $educationLevel->name,
'data' => $educationLevel->toArray(),
]
);
$educationLevel->delete();
return redirect()->route('education_levels.index');
}

View File

@ -15,8 +15,21 @@ class StoreEducationLevelRequest extends FormRequest
{
return [
'name' => 'required|string|max:255|unique:education_levels,name',
'description' => 'string',
'slug' => 'required|string|max:255|unique:education_levels,slug',
'description' => 'nullable|string',
'slug' => 'nullable|string|max:255|unique:education_levels,slug',
];
}
public function messages(): array
{
return [
'name.required' => 'Поле название обязательно.',
'name.string' => 'Поле название должен быть строкой.',
'name.max' => 'Поле название не должен превышать :max символов.',
'name.unique' => 'Название уже занят.',
'description.string' => 'Поле описание должен быть строкой.',
'slug.string' => 'Поле URL должен быть строкой.',
'slug.max' => 'Поле URL не должен превышать :max символов.',
];
}
}

View File

@ -15,8 +15,21 @@ class UpdateEducationLevelRequest extends FormRequest
{
return [
'name' => "required|string|max:255|unique:education_levels,name,{$this->education_level->id}",
'description' => 'string',
'description' => 'nullable|string',
'slug' => "required|string|max:255|unique:education_levels,slug,{$this->education_level->id}",
];
}
public function messages(): array
{
return [
'name.required' => 'Поле название обязательно.',
'name.string' => 'Поле название должен быть строкой.',
'name.max' => 'Поле название не должен превышать :max символов.',
'name.unique' => 'Название уже занят.',
'description.string' => 'Поле описание должен быть строкой.',
'slug.string' => 'Поле URL должен быть строкой.',
'slug.max' => 'Поле URL не должен превышать :max символов.',
];
}
}

View File

@ -64,4 +64,9 @@ return [
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере'
],
'education_levels' => [
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере'
],
];

View File

@ -4,39 +4,43 @@
<div class="row">
<div class="col">
<h1 class=""> Создать Уровень Образования</h1>
{{ Form::open(['url' => route('education_levels.store'), 'method' => 'POST', 'class' => '']) }}
{{ Form::open(['url' => route('education_levels.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('name', 'Название') }}
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_levels.name')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control']) }}
{{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_levels.name'), 'required']) }}
<div class="invalid-feedback">
Поле "Название" обязательно!
</div>
<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.education_levels.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.education_levels.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.education_levels.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.education_levels.slug')]) }}
</div>
<div>
<div class="text-danger">
@if ($errors->any())
{{ $errors->first('slug') }}
@endif

View File

@ -5,39 +5,43 @@
<div class="row">
<div class="col">
<h1 class="">Езменить уровень образования</h1>
{{ Form::open(['url' => route('education_levels.update', $educationLevel), 'method' => 'PATCH', 'class' => '']) }}
{{ Form::open(['url' => route('education_levels.update', $educationLevel), 'method' => 'PATCH', 'class' => 'needs-validation', 'novalidate']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('name', 'Название') }}
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.name')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::text('name', $educationLevel->name, ['class' => 'form-control']) }}
<div class="invalid-feedback">
Поле "Название" обязательно!
</div>
<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.faculty.description')]) }}
</div>
<div class="mt-1">
{{ Form::text('description', $educationLevel->description, ['class' => 'form-control']) }}
{{ Form::text('description', $educationLevel->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.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.faculty.slug')]) }}
</div>
<div class="mt-1">
{{ Form::text('slug', $educationLevel->slug, ['class' => 'form-control']) }}
{{ Form::text('slug', $educationLevel->slug, ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
</div>
<div>
<div class="text-danger">
@if ($errors->any())
{{ $errors->first('slug') }}
@endif