add unique field for faculty and bootstrap validation for Faculty
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Successful in 1m50s Details
Tests & Lint & Deploy to Railway / deploy (push) Failing after 6s Details

This commit is contained in:
aslan 2024-03-06 15:22:07 +03:00
parent d3c6a8336a
commit 2c209f5ddc
3 changed files with 45 additions and 14 deletions

View File

@ -31,7 +31,14 @@ class FacultyController extends Controller
{
$validated = $request->validated();
$slug = $validated['slug'] === null ? Str::slug($validated['name']) : $validated['slug'];
if ($validated['slug'] === null) {
$transliterationSlug = Str::slug($validated['name']);
$randomNumber = random_int(100, 999);
$slug = "{$transliterationSlug}-{$randomNumber}";
} else {
$slug = $validated['slug'];
}
$faculty = new Faculty();
$faculty->name = $validated['name'];
$faculty->description = $validated['description'];

View File

@ -10,10 +10,10 @@ return new class extends Migration
{
Schema::create('faculties', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('name')->unique();
$table->text('description')->nullable();
$table->integer('position');
$table->string('slug');
$table->string('slug')->unique();
$table->foreignId('educational_institution_id')->constrained('educational_institutions');
$table->timestamps();
});

View File

@ -5,14 +5,17 @@
<div class="row">
<div class="col">
<h1 class=""> Создать факультет</h1>
{{ Form::open(['url' => route('faculties.store'), 'method' => 'POST', 'class' => '']) }}
{{ Form::open(['url' => route('faculties.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.position')]) }}
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.position')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::number('position', PositionHelper::faculty(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.position')]) }}
{{ Form::number('position', PositionHelper::faculty(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.position'), 'required']) }}
<div class="invalid-feedback">
Поле "Позиция" обязательно!
</div>
</div>
<div class="text-danger">
@if ($errors->any())
@ -21,11 +24,14 @@
</div>
<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', '', ['class' => 'form-control']) }}
{{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.name'), 'required']) }}
<div class="invalid-feedback">
Поле "Название" обязательно!
</div>
</div>
<div class="text-danger">
@if ($errors->any())
@ -34,10 +40,10 @@
</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', '', ['class' => 'form-control']) }}
{{ Form::text('description', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.description')]) }}
</div>
<div class="text-danger">
@if ($errors->any())
@ -45,11 +51,11 @@
@endif
</div>
<div class="mt-3">
{{ Form::label('educational_institution_id', 'Учебное заведение') }}
{{ Form::label('educational_institution_id', 'Учебное заведение', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.educational_institution_id')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::select('educational_institution_id', $educationalInstitutions, null, ['class' => 'form-select']) }}
{{ Form::select('educational_institution_id', $educationalInstitutions, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.educational_institution_id')]) }}
</div>
<div class="text-danger">
@if ($errors->any())
@ -57,10 +63,10 @@
@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', '', ['class' => 'form-control']) }}
{{ Form::text('slug', '', ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.slug')]) }}
</div>
<div class="text-danger">
@if ($errors->any())
@ -75,4 +81,22 @@
</div>
</div>
@endauth
<script>
(function () {
'use strict'
var forms = document.querySelectorAll('.needs-validation')
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
</script>
@endsection