add unique field for faculty and bootstrap validation for Faculty
This commit is contained in:
parent
d3c6a8336a
commit
2c209f5ddc
|
@ -31,7 +31,14 @@ class FacultyController extends Controller
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$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 = new Faculty();
|
||||||
$faculty->name = $validated['name'];
|
$faculty->name = $validated['name'];
|
||||||
$faculty->description = $validated['description'];
|
$faculty->description = $validated['description'];
|
||||||
|
|
|
@ -10,10 +10,10 @@ return new class extends Migration
|
||||||
{
|
{
|
||||||
Schema::create('faculties', function (Blueprint $table) {
|
Schema::create('faculties', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name')->unique();
|
||||||
$table->text('description')->nullable();
|
$table->text('description')->nullable();
|
||||||
$table->integer('position');
|
$table->integer('position');
|
||||||
$table->string('slug');
|
$table->string('slug')->unique();
|
||||||
$table->foreignId('educational_institution_id')->constrained('educational_institutions');
|
$table->foreignId('educational_institution_id')->constrained('educational_institutions');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,14 +5,17 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1 class=""> Создать факультет</h1>
|
<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="col">
|
||||||
<div class="mt-3">
|
<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>
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<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>
|
||||||
<div class="text-danger">
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
@ -21,11 +24,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<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>
|
<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.faculty.name'), 'required']) }}
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
Поле "Название" обязательно!
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-danger">
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
@ -34,10 +40,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::label('description', 'Описание') }}
|
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.faculty.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.faculty.description')]) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-danger">
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
@ -45,11 +51,11 @@
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-3">
|
<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>
|
<span class="text-danger">*</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-1">
|
<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>
|
||||||
<div class="text-danger">
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
@ -57,10 +63,10 @@
|
||||||
@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 class="text-danger">
|
<div class="text-danger">
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
@ -75,4 +81,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@endauth
|
@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
|
@endsection
|
||||||
|
|
Loading…
Reference in New Issue