forked from aslan/applicant-site
add bootstrap validation and Logging for Educational Institution
This commit is contained in:
parent
8a6e1bea3d
commit
7f2f24ca59
|
@ -9,6 +9,8 @@ use App\Models\EducationalInstitution;
|
||||||
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 EducationalInstitutionController extends Controller
|
class EducationalInstitutionController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -34,6 +36,16 @@ class EducationalInstitutionController extends Controller
|
||||||
$educationalInstitution->position = $validated['position'];
|
$educationalInstitution->position = $validated['position'];
|
||||||
$educationalInstitution->save();
|
$educationalInstitution->save();
|
||||||
|
|
||||||
|
Log::channel('app')
|
||||||
|
->info(
|
||||||
|
'CREATE учеб. заведение {educationalInstitution} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationalInstitution' => $educationalInstitution->name,
|
||||||
|
'data' => $validated
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return redirect()->route('educational_institutions.index');
|
return redirect()->route('educational_institutions.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,11 +62,24 @@ class EducationalInstitutionController extends Controller
|
||||||
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
|
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
$oldData = $educationalInstitution->toArray();
|
||||||
|
|
||||||
$educationalInstitution->name = $validated['name'];
|
$educationalInstitution->name = $validated['name'];
|
||||||
$educationalInstitution->description = $validated['description'];
|
$educationalInstitution->description = $validated['description'];
|
||||||
$educationalInstitution->position = $validated['position'];
|
$educationalInstitution->position = $validated['position'];
|
||||||
$educationalInstitution->slug = $validated['slug'];
|
$educationalInstitution->slug = $validated['slug'];
|
||||||
|
|
||||||
|
Log::channel('app')
|
||||||
|
->warning(
|
||||||
|
'UPDATE учеб. заведение {educationalInstitution} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'faculty' => $educationalInstitution->name,
|
||||||
|
'oldData' => $oldData,
|
||||||
|
'newData' => $validated
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
$educationalInstitution->save();
|
$educationalInstitution->save();
|
||||||
|
|
||||||
return redirect()->route('educational_institutions.index');
|
return redirect()->route('educational_institutions.index');
|
||||||
|
@ -63,8 +88,26 @@ class EducationalInstitutionController extends Controller
|
||||||
public function destroy(EducationalInstitution $educationalInstitution)
|
public function destroy(EducationalInstitution $educationalInstitution)
|
||||||
{
|
{
|
||||||
if ($educationalInstitution->faculties()->exists()) {
|
if ($educationalInstitution->faculties()->exists()) {
|
||||||
|
Log::channel('app')
|
||||||
|
->error(
|
||||||
|
'NOT DELETE учеб. заведение {educationalInstitution} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationalInstitution' => $educationalInstitution->name,
|
||||||
|
'data' => $educationalInstitution->toArray(),
|
||||||
|
]
|
||||||
|
);
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
Log::channel('app')
|
||||||
|
->critical(
|
||||||
|
'DELETE учеб. заведение {educationalInstitution} - user {user}',
|
||||||
|
[
|
||||||
|
'user' => Auth::user()->name,
|
||||||
|
'educationalInstitution' => $educationalInstitution->name,
|
||||||
|
'data' => $educationalInstitution->toArray(),
|
||||||
|
]
|
||||||
|
);
|
||||||
$educationalInstitution->delete();
|
$educationalInstitution->delete();
|
||||||
|
|
||||||
return redirect()->route('educational_institutions.index');
|
return redirect()->route('educational_institutions.index');
|
||||||
|
|
|
@ -16,8 +16,24 @@ class StoreEducationalInstitutionRequest extends FormRequest
|
||||||
return [
|
return [
|
||||||
'position' => 'required|int|numeric|max:255',
|
'position' => 'required|int|numeric|max:255',
|
||||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||||
'description' => 'string',
|
'description' => 'nullable|string',
|
||||||
'slug' => 'required|string|max:255|unique:educational_institutions,slug',
|
'slug' => 'nullable|string|max:255|unique:educational_institutions,slug',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
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 UpdateEducationalInstitutionRequest extends FormRequest
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'position' => 'required|int|numeric|max:255',
|
'position' => 'required|int|numeric|max:255',
|
||||||
'description' => 'string',
|
'description' => 'nullable|string',
|
||||||
'slug' => [
|
'slug' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
|
@ -31,4 +31,21 @@ class UpdateEducationalInstitutionRequest extends FormRequest
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 символов.',
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<span class="text-danger">*</span>
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
{{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.name'), 'required']) }}
|
{{ Form::number('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.name'), 'required']) }}
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
Поле "Название" обязательно!
|
Поле "Название" обязательно!
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,50 +4,58 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1 class="">Изменить учебное заведение</h1>
|
<h1 class="">Изменить учебное заведение</h1>
|
||||||
{{ Form::model($educationalInstitution, ['route' => ['educational_institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => '']) }}
|
{{ Form::model($educationalInstitution, ['route' => ['educational_institutions.update', $educationalInstitution], 'method' => 'PATCH', 'class' => 'needs-validation', 'novalidate']) }}
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<div>
|
|
||||||
{{ Form::label('position', 'Позиция') }}
|
|
||||||
</div>
|
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
{{ Form::text('position', $educationalInstitution->position, ['class' => 'form-control']) }}
|
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.position')]) }}
|
||||||
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="mt-1">
|
||||||
|
{{ Form::number('position', $educationalInstitution->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.position'), 'required']) }}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Поле "Позиция" обязательно!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('position') }}
|
{{ $errors->first('position') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ Form::label('name', 'Название') }}
|
|
||||||
</div>
|
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
{{ Form::text('name', $educationalInstitution->name, ['class' => 'form-control']) }}
|
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.name')]) }}
|
||||||
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="mt-1">
|
||||||
|
{{ Form::text('name', $educationalInstitution->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.name'), 'required']) }}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Поле "Название" обязательно!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
{{ $errors->first('name') }}
|
{{ $errors->first('name') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ Form::label('description', 'Описание') }}
|
|
||||||
</div>
|
|
||||||
<div class="mt-2">
|
<div class="mt-2">
|
||||||
{{ Form::text('description', $educationalInstitution->description, ['class' => 'form-control']) }}
|
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div class="mt-1">
|
||||||
|
{{ Form::text('description', $educationalInstitution->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.description')]) }}
|
||||||
|
</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-2">
|
||||||
{{ Form::label('slug', 'URL') }}
|
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<div class="mt-1">
|
||||||
{{ Form::text('slug', $educationalInstitution->slug, ['class' => 'form-control']) }}
|
{{ Form::text('slug', $educationalInstitution->slug, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.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