forked from aslan/applicant-site
add bootstrap validation and Logging for Education Form
This commit is contained in:
parent
299817069e
commit
2104362d4e
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\admin\Catalog\Direction;
|
namespace App\Http\Controllers\admin\Catalog\Direction;
|
||||||
|
|
||||||
|
use App\Helpers\SlugHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\admin\Catalog\Direction\StoreEducationFormRequest;
|
use App\Http\Requests\admin\Catalog\Direction\StoreEducationFormRequest;
|
||||||
use App\Http\Requests\admin\Catalog\Direction\UpdateEducationFormRequest;
|
use App\Http\Requests\admin\Catalog\Direction\UpdateEducationFormRequest;
|
||||||
|
@ -9,6 +10,8 @@ use App\Models\EducationForm;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class EducationFormController extends Controller
|
class EducationFormController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -26,12 +29,20 @@ class EducationFormController extends Controller
|
||||||
public function store(StoreEducationFormRequest $request)
|
public function store(StoreEducationFormRequest $request)
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
|
$slug = SlugHelper::get($validated);
|
||||||
|
|
||||||
$form = new EducationForm();
|
$form = new EducationForm();
|
||||||
$form->name = $validated['name'];
|
$form->name = $validated['name'];
|
||||||
$form->description = $validated['description'];
|
$form->description = $validated['description'];
|
||||||
$form->slug = $validated['slug'];
|
$form->slug = $slug;
|
||||||
$form->save();
|
$form->save();
|
||||||
|
|
||||||
|
Log::channel('app')
|
||||||
|
->info(
|
||||||
|
'CREATE форма образования {educationForm} - user {user}',
|
||||||
|
['user' => Auth::user()->name, 'educationForm' => $form->name, 'data' => $validated]
|
||||||
|
);
|
||||||
return redirect()->route('education_forms.index');
|
return redirect()->route('education_forms.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,10 +60,23 @@ class EducationFormController extends Controller
|
||||||
public function update(UpdateEducationFormRequest $request, EducationForm $educationForm)
|
public function update(UpdateEducationFormRequest $request, EducationForm $educationForm)
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
$oldData = $educationForm->toArray();
|
||||||
|
|
||||||
$educationForm->name = $validated['name'];
|
$educationForm->name = $validated['name'];
|
||||||
$educationForm->description = $validated['description'];
|
$educationForm->description = $validated['description'];
|
||||||
$educationForm->slug = $validated['slug'];
|
$educationForm->slug = $validated['slug'];
|
||||||
|
|
||||||
|
Log::channel('app')
|
||||||
|
->warning(
|
||||||
|
'UPDATE форма образования {educationForm} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationForm' => $educationForm->name,
|
||||||
|
'oldData' => $oldData,
|
||||||
|
'newData' => $validated
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$educationForm->save();
|
$educationForm->save();
|
||||||
|
|
||||||
return redirect()->route('education_forms.index');
|
return redirect()->route('education_forms.index');
|
||||||
|
@ -61,8 +85,26 @@ class EducationFormController extends Controller
|
||||||
public function destroy(EducationForm $educationForm)
|
public function destroy(EducationForm $educationForm)
|
||||||
{
|
{
|
||||||
if ($educationForm->directions()->exists()) {
|
if ($educationForm->directions()->exists()) {
|
||||||
|
Log::channel('app')
|
||||||
|
->error(
|
||||||
|
'NOT DELETE форма образования {educationForm} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationForm' => $educationForm->name,
|
||||||
|
'data' => $educationForm->toArray(),
|
||||||
|
]
|
||||||
|
);
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
Log::channel('app')
|
||||||
|
->critical(
|
||||||
|
'DELETE факультет {faculty} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationForm' => $educationForm->name,
|
||||||
|
'data' => $educationForm->toArray(),
|
||||||
|
]
|
||||||
|
);
|
||||||
$educationForm->delete();
|
$educationForm->delete();
|
||||||
return redirect()->route('education_forms.index');
|
return redirect()->route('education_forms.index');
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,21 @@ class StoreEducationFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'required|string|max:255|unique:education_levels,name',
|
'name' => 'required|string|max:255|unique:education_levels,name',
|
||||||
'description' => 'string',
|
'description' => 'nullable|string',
|
||||||
'slug' => 'required|string|max:255|unique:education_levels,slug',
|
'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 символов.',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,21 @@ class UpdateEducationFormRequest extends FormRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => "required|string|max:255|unique:education_forms,name,{$this->education_form->id}",
|
'name' => "required|string|max:255|unique:education_forms,name,{$this->education_form->id}",
|
||||||
'description' => 'string',
|
'description' => 'nullable|string',
|
||||||
'slug' => "required|string|max:255|unique:education_forms,slug,{$this->education_form->id}",
|
'slug' => "required|string|max:255|unique:education_forms,slug,{$this->education_form->id}",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name.required' => 'Поле название обязательно.',
|
||||||
|
'name.string' => 'Поле название должен быть строкой.',
|
||||||
|
'name.max' => 'Поле название не должен превышать :max символов.',
|
||||||
|
'name.unique' => 'Название уже занят.',
|
||||||
|
'description.string' => 'Поле описание должен быть строкой.',
|
||||||
|
'slug.string' => 'Поле URL должен быть строкой.',
|
||||||
|
'slug.max' => 'Поле URL не должен превышать :max символов.',
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,4 +69,9 @@ return [
|
||||||
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||||
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||||
],
|
],
|
||||||
|
'education_forms' => [
|
||||||
|
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
|
||||||
|
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||||
|
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -4,39 +4,43 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1 class=""> Создать форму Образования</h1>
|
<h1 class=""> Создать форму Образования</h1>
|
||||||
{{ Form::open(['url' => route('education_forms.store'), 'method' => 'POST', 'class' => '']) }}
|
{{ Form::open(['url' => route('education_forms.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('name', 'Название') }}
|
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.position')]) }}
|
||||||
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<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_forms.name'), 'required']) }}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Поле "Название" обязательно!
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('name') }}
|
{{ $errors->first('name') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('description', 'Описание') }}
|
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<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_forms.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('description') }}
|
{{ $errors->first('description') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('slug', 'URL') }}
|
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('slug', '', ['class' => 'form-control']) }}
|
{{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('slug') }}
|
{{ $errors->first('slug') }}
|
||||||
@endif
|
@endif
|
||||||
|
|
|
@ -5,39 +5,43 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1 class="">Изменить форму образования</h1>
|
<h1 class="">Изменить форму образования</h1>
|
||||||
{{ Form::open(['url' => route('education_forms.update', $educationForm), 'method' => 'PATCH', 'class' => '']) }}
|
{{ Form::open(['url' => route('education_forms.update', $educationForm), 'method' => 'PATCH', 'class' => 'needs-validation', 'novalidate']) }}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('name', 'Название') }}
|
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.name')]) }}
|
||||||
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('name', $educationForm->name, ['class' => 'form-control']) }}
|
{{ Form::text('name', $educationForm->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.name'), 'required']) }}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Поле "Название" обязательно!
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('name') }}
|
{{ $errors->first('name') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('description', 'Описание') }}
|
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('description', $educationForm->description, ['class' => 'form-control']) }}
|
{{ Form::text('description', $educationForm->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.education_forms.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('description') }}
|
{{ $errors->first('description') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('slug', 'URL') }}
|
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('slug', $educationForm->slug, ['class' => 'form-control']) }}
|
{{ Form::text('slug', $educationForm->slug, ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('slug') }}
|
{{ $errors->first('slug') }}
|
||||||
@endif
|
@endif
|
||||||
|
|
Loading…
Reference in New Issue