add bootstrap validated and logging to Subject Type Profile
Tests & Lint & Deploy to Railway / deploy (push) Blocked by required conditions Details
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Has been cancelled Details

This commit is contained in:
aslan 2024-03-12 12:40:05 +03:00
parent 64ad13f96f
commit 40414f6da8
7 changed files with 158 additions and 50 deletions

View File

@ -6,6 +6,7 @@ use App\Models\Direction;
use App\Models\DirectionProfile; use App\Models\DirectionProfile;
use App\Models\Faculty; use App\Models\Faculty;
use App\Models\EducationalInstitution; use App\Models\EducationalInstitution;
use App\Models\SubjectType;
class PositionHelper class PositionHelper
{ {
@ -27,9 +28,15 @@ class PositionHelper
return $maxPosition >= 254 ? 255 : $maxPosition + 1; return $maxPosition >= 254 ? 255 : $maxPosition + 1;
} }
public static function directionProfiles() public static function directionProfile()
{ {
$maxPosition = DirectionProfile::max('position'); $maxPosition = DirectionProfile::max('position');
return $maxPosition >= 254 ? 255 : $maxPosition + 1; return $maxPosition >= 254 ? 255 : $maxPosition + 1;
} }
public static function subjectType()
{
$maxPosition = SubjectType::max('position');
return $maxPosition >= 254 ? 255 : $maxPosition + 1;
}
} }

View File

@ -2,12 +2,16 @@
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\StoreSubjectTypeRequest; use App\Http\Requests\admin\Catalog\Direction\StoreSubjectTypeRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateSubjectTypeRequest; use App\Http\Requests\admin\Catalog\Direction\UpdateSubjectTypeRequest;
use App\Models\SubjectType; use App\Models\SubjectType;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class SubjectTypeController extends Controller class SubjectTypeController extends Controller
{ {
@ -26,13 +30,21 @@ class SubjectTypeController extends Controller
{ {
$validated = $request->validated(); $validated = $request->validated();
$slug = SlugHelper::get($validated);
$type = new SubjectType(); $type = new SubjectType();
$type->name = $validated['name']; $type->name = $validated['name'];
$type->description = $validated['description']; $type->description = $validated['description'];
$type->slug = $validated['slug']; $type->slug = $slug;
$type->position = $validated['position']; $type->position = $validated['position'];
$type->save(); $type->save();
Log::channel('app')
->info(
'CREATE тип предмета {subjectType} - user {user}',
['user' => Auth::user()->name, 'subjectType' => $type->name, 'data' => $validated]
);
return redirect()->route('subject_types.index'); return redirect()->route('subject_types.index');
} }
@ -49,6 +61,7 @@ class SubjectTypeController extends Controller
public function update(UpdateSubjectTypeRequest $request, SubjectType $subjectType): RedirectResponse public function update(UpdateSubjectTypeRequest $request, SubjectType $subjectType): RedirectResponse
{ {
$validated = $request->validated(); $validated = $request->validated();
$oldData = $subjectType->toArray();
$subjectType->name = $validated['name']; $subjectType->name = $validated['name'];
$subjectType->description = $validated['description']; $subjectType->description = $validated['description'];
@ -56,14 +69,43 @@ class SubjectTypeController extends Controller
$subjectType->position = $validated['position']; $subjectType->position = $validated['position'];
$subjectType->save(); $subjectType->save();
Log::channel('app')
->warning(
'UPDATE тип предмета {subjectType} - user {user}',
[
'user' => Auth::user()->name,
'subjectType' => $subjectType->name,
'oldData' => $oldData,
'newData' => $validated
]
);
return redirect()->route('subject_types.index'); return redirect()->route('subject_types.index');
} }
public function destroy(SubjectType $subjectType): RedirectResponse public function destroy(SubjectType $subjectType): RedirectResponse
{ {
if ($subjectType->entranceExaminations()->exists()) { if ($subjectType->entranceExaminations()->exists()) {
Log::channel('app')
->error(
'NOT DELETE тип предмета {subjectType} - user {user}',
[
'user' => Auth::user()->name,
'subjectType' => $subjectType->name,
'data' => $subjectType->toArray(),
]
);
return back(); return back();
} }
Log::channel('app')
->critical(
'DELETE тип предмета {subjectType} - user {user}',
[
'user' => Auth::user()->name,
'subjectType' => $subjectType->name,
'data' => $subjectType->toArray(),
]
);
$subjectType->delete(); $subjectType->delete();
return redirect()->route('subject_types.index'); return redirect()->route('subject_types.index');
} }

View File

@ -14,10 +14,27 @@ class StoreSubjectTypeRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'position' => 'required|int|numeric|max:255',
'name' => 'required|string|max:255|unique:subject_types,name', 'name' => 'required|string|max:255|unique:subject_types,name',
'description' => 'string', 'description' => 'nullable|string',
'slug' => 'required|string|max:255|unique:subject_types,slug', 'slug' => 'nullable|string|max:255|unique:subject_types,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 символов.',
]; ];
} }
} }

View File

@ -15,7 +15,7 @@ class UpdateSubjectTypeRequest extends FormRequest
{ {
return [ return [
'position' => 'required|int|numeric|max:255', 'position' => 'required|int|numeric|max:255',
'description' => 'string', 'description' => 'nullable|string',
'slug' => [ 'slug' => [
'string', 'string',
'required', 'required',
@ -30,4 +30,21 @@ class UpdateSubjectTypeRequest 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 символов.',
];
}
} }

View File

@ -45,5 +45,11 @@ return [
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте', 'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
'description' => 'Поле "Описание" может быть пустым для отображения на сайте', 'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере' 'slug' => 'Поле "URL" нужно для отображения в браузере'
],
'subject_types' => [
'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте',
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере'
] ]
]; ];

View File

@ -1,59 +1,69 @@
@php use App\Helpers\PositionHelper; @endphp
@extends('layouts.admin_layout') @extends('layouts.admin_layout')
@section('content') @section('content')
@auth() @auth()
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class=""> Создать Тип предмета</h1> <h1 class=""> Создать Тип предмета</h1>
{{ Form::open(['url' => route('subject_types.store'), 'method' => 'POST', 'class' => '']) }} {{ Form::open(['url' => route('subject_types.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('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.position')]) }}
<span class="text-danger">*</span>
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control']) }} {{ Form::text('position', PositionHelper::subjectType(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.position'), 'required']) }}
<div class="invalid-feedback">
Поле "Позиция" обязательно!
</div> </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.subject_types.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.subject_types.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 class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.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.subject_types.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.subject_types.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.subject_types.slug')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('slug') }} {{ $errors->first('slug') }}
@endif @endif
</div> </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"> <div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div> </div>

View File

@ -5,56 +5,65 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class="">Изменить тип предмета</h1> <h1 class="">Изменить тип предмета</h1>
{{ Form::open(['url' => route('subject_types.update', $subjectType), 'method' => 'PATCH', 'class' => '']) }} {{ Form::open(['url' => route('subject_types.update', $subjectType), '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('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.position')]) }}
<span class="text-danger">*</span>
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('name', $subjectType->name, ['class' => 'form-control']) }} {{ Form::text('position', $subjectType->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.position'), 'required']) }}
<div class="invalid-feedback">
Поле "Позиция" обязательно!
</div> </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.subject_types.name')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::text('name', $subjectType->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.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 class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.description')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('description', $subjectType->description, ['class' => 'form-control']) }} {{ Form::text('description', $subjectType->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.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.subject_types.slug')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('slug', $subjectType->slug, ['class' => 'form-control']) }} {{ Form::text('slug', $subjectType->slug, ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.subject_types.slug')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('slug') }} {{ $errors->first('slug') }}
@endif @endif
</div> </div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $subjectType->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3"> <div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div> </div>