Compare commits
3 Commits
6230a15d17
...
8a6e1bea3d
Author | SHA1 | Date |
---|---|---|
aslan | 8a6e1bea3d | |
aslan | ebe604293f | |
aslan | 5fa4b20ec7 |
|
@ -60,4 +60,10 @@ class PositionHelper
|
|||
$maxPosition = EntranceExamination::max('position');
|
||||
return $maxPosition >= 254 ? 255 : $maxPosition + 1;
|
||||
}
|
||||
|
||||
public static function department()
|
||||
{
|
||||
$maxPosition = EntranceExamination::max('position');
|
||||
return $maxPosition >= 254 ? 255 : $maxPosition + 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\admin\Catalog;
|
||||
|
||||
use App\Helpers\SlugHelper;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\admin\Catalog\StoreDepartmentRequest;
|
||||
use App\Http\Requests\admin\Catalog\UpdateDepartmentRequest;
|
||||
|
@ -11,6 +12,8 @@ use Illuminate\Contracts\View\Factory;
|
|||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
|
@ -30,6 +33,8 @@ class DepartmentController extends Controller
|
|||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$slug = SlugHelper::get($validated);
|
||||
|
||||
$department = new Department();
|
||||
$department->name = $validated['name'];
|
||||
$department->description = $validated['description'];
|
||||
|
@ -38,6 +43,12 @@ class DepartmentController extends Controller
|
|||
$department->slug = $validated['slug'];
|
||||
$department->save();
|
||||
|
||||
Log::channel('app')
|
||||
->info(
|
||||
'CREATE кафедра {department} - user {user}',
|
||||
['user' => Auth::user()->name, 'department' => $department->name, 'data' => $validated]
|
||||
);
|
||||
|
||||
return redirect()->route('departments.index');
|
||||
}
|
||||
|
||||
|
@ -57,12 +68,25 @@ class DepartmentController extends Controller
|
|||
public function update(UpdateDepartmentRequest $request, Department $department): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$oldData = $department->toArray();
|
||||
|
||||
$department->name = $validated['name'];
|
||||
$department->description = $validated['description'];
|
||||
$department->position = $validated['position'];
|
||||
$department->faculty_id = $validated['faculty_id'];
|
||||
$department->slug = $validated['slug'];
|
||||
|
||||
Log::channel('app')
|
||||
->warning(
|
||||
'UPDATE кафедра {department} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'department' => $department->name,
|
||||
'oldData' => $oldData,
|
||||
'newData' => $validated
|
||||
]
|
||||
);
|
||||
|
||||
$department->save();
|
||||
|
||||
return redirect()->route('departments.index');
|
||||
|
@ -71,8 +95,26 @@ class DepartmentController extends Controller
|
|||
public function destroy(Department $department): RedirectResponse
|
||||
{
|
||||
if ($department->directions()->exists()) {
|
||||
Log::channel('app')
|
||||
->error(
|
||||
'NOT DELETE кафедра {department} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'department' => $department->name,
|
||||
'data' => $department->toArray(),
|
||||
]
|
||||
);
|
||||
return back();
|
||||
}
|
||||
Log::channel('app')
|
||||
->critical(
|
||||
'DELETE кафедра {department} - user {user}',
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'department' => $department->name,
|
||||
'data' => $department->toArray(),
|
||||
]
|
||||
);
|
||||
$department->delete();
|
||||
return redirect()->route('departments.index');
|
||||
}
|
||||
|
|
|
@ -56,7 +56,11 @@ class EntranceExaminationController extends Controller
|
|||
Log::channel('app')
|
||||
->info(
|
||||
'CREATE вступ. испытания {entranceExamination} - user {user}',
|
||||
['user' => Auth::user()->name, 'entranceExamination' => $entranceExamination->name, 'data' => $validated]
|
||||
[
|
||||
'user' => Auth::user()->name,
|
||||
'entranceExamination' => $entranceExamination->name,
|
||||
'data' => $validated
|
||||
]
|
||||
);
|
||||
|
||||
return redirect()->route('entrance_examinations.index');
|
||||
|
|
|
@ -17,9 +17,30 @@ class StoreDepartmentRequest extends FormRequest
|
|||
return [
|
||||
'position' => 'required|int|numeric|max:255',
|
||||
'name' => 'required|string|max:255|unique:departments,name',
|
||||
'description' => 'string',
|
||||
'slug' => 'required|string|max:255|unique:departments,slug',
|
||||
'description' => 'nullable|string',
|
||||
'slug' => 'nullable|string|max:255|unique:departments,slug',
|
||||
'faculty_id' => 'required|numeric|int|max:1000',
|
||||
];
|
||||
}
|
||||
|
||||
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 символов.',
|
||||
'faculty_id.required' => 'Поле учебное заведение обязательно.',
|
||||
'faculty_id.int' => 'Учебное заведение должно быть целым числом.',
|
||||
'faculty_id.numeric' => 'Учебное заведение должно быть числом.',
|
||||
'faculty_id.max' => 'Поле учебное заведение не должен быть больше :max.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class UpdateDepartmentRequest extends FormRequest
|
|||
{
|
||||
return [
|
||||
'position' => 'required|int|numeric|max:255',
|
||||
'description' => 'string',
|
||||
'description' => 'nullable|string',
|
||||
'slug' => [
|
||||
'string',
|
||||
'required',
|
||||
|
@ -30,4 +30,25 @@ class UpdateDepartmentRequest 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 символов.',
|
||||
'faculty_id.required' => 'Поле учебное заведение обязательно.',
|
||||
'faculty_id.int' => 'Учебное заведение должно быть целым числом.',
|
||||
'faculty_id.numeric' => 'Учебное заведение должно быть числом.',
|
||||
'faculty_id.max' => 'Поле учебное заведение не должен быть больше :max.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,11 @@ return [
|
|||
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||
],
|
||||
'departments' => [
|
||||
'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте',
|
||||
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
|
||||
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
|
||||
'faculty_id' => 'Поле "Факультет" указывает на привязку к факультету',
|
||||
'slug' => 'Поле "URL" нужно для отображения в браузере'
|
||||
],
|
||||
];
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
@php use App\Helpers\PositionHelper; @endphp
|
||||
@extends('layouts.admin_layout')
|
||||
@section('content')
|
||||
@auth()
|
||||
|
@ -6,60 +7,71 @@
|
|||
<h1 class=""> Создать кафедру</h1>
|
||||
{{ Form::open(['url' => route('departments.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
<div class="col">
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.position')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', '', ['class' => 'form-control']) }}
|
||||
{{ Form::number('position', PositionHelper::department(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.position'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Позиция" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.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.departments.name'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Название" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.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.departments.description')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('faculty_id', 'Факультет') }}
|
||||
{{ Form::label('faculty_id', 'Факультет', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.faculty_id')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('faculty_id', $faculties, null, ['class' => 'form-select']) }}
|
||||
{{ Form::select('faculty_id', $faculties, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.faculty_id')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('faculty_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.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.departments.slug')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
|
|
|
@ -7,59 +7,68 @@
|
|||
{{ Form::open(['url' => route('departments.update', $department), 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div class="mt-3">
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
{{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.position')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('position', $department->position, ['class' => 'form-control']) }}
|
||||
{{ Form::number('position', $department->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.position'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Позиция" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('name', 'Название') }}
|
||||
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.name')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('name', $department->name, ['class' => 'form-control']) }}
|
||||
{{ Form::text('name', $department->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.name'), 'required']) }}
|
||||
<div class="invalid-feedback">
|
||||
Поле "Название" обязательно!
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
{{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.description')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('description', $department->description, ['class' => 'form-control']) }}
|
||||
{{ Form::text('description', $department->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.description')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{{ Form::label('educational_institution_id', 'Факультет') }}
|
||||
{{ Form::label('faculty_id', 'Факультет', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.faculty_id')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::select('faculty_id', $faculties, $department->faculty->id, ['class' => 'form-select']) }}
|
||||
{{ Form::select('faculty_id', $faculties, $department->faculty->id, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.faculty_id')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('educational_institution_id') }}
|
||||
{{ $errors->first('faculty_id') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="mt-3">
|
||||
{{ Form::label('slug', 'URL') }}
|
||||
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.slug')]) }}
|
||||
</div>
|
||||
<div class="mt-1">
|
||||
{{ Form::text('slug', $department->slug, ['class' => 'form-control']) }}
|
||||
{{ Form::text('slug', $department->slug, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.departments.slug')]) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-danger">
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('slug') }}
|
||||
@endif
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<h1 class=""> Создать факультет</h1>
|
||||
{{ 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.faculty.position')]) }}
|
||||
<span class="text-danger">*</span>
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
// use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function testTheApplicationReturnsASuccessfulResponse(): void
|
||||
{
|
||||
$response = $this->get('/');
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue