diff --git a/app/Http/Controllers/Catalog/DepartmentController.php b/app/Http/Controllers/Catalog/DepartmentController.php new file mode 100644 index 0000000..91b1869 --- /dev/null +++ b/app/Http/Controllers/Catalog/DepartmentController.php @@ -0,0 +1,75 @@ +validated(); + + $department = new Department(); + $department->name = $validated['name']; + $department->description = $validated['description']; + $department->position = $validated['position']; + $department->faculty_id = $validated['faculty_id']; + $department->save(); + + return redirect()->route('departments.index'); + } + + public function show(Department $department): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + return view('catalog.department.show', compact('department')); + } + + public function edit(Department $department): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + $faculties = Faculty::pluck('name', 'id'); + return view('catalog.department.edit', compact('department', 'faculties')); + } + + /** + * Update the specified resource in storage. + */ + public function update(UpdateDepartmentRequest $request, Department $department) + { + $validated = $request->validated(); + + $department->name = $validated['name']; + $department->description = $validated['description']; + $department->position = $validated['position']; + $department->faculty_id = $validated['faculty_id']; + $department->save(); + + return redirect()->route('departments.index'); + } + + public function destroy(Department $department): RedirectResponse + { + $department->delete(); + return redirect()->route('departments.index'); + } +} diff --git a/app/Http/Requests/StoreDepartmentRequest.php b/app/Http/Requests/StoreDepartmentRequest.php new file mode 100644 index 0000000..ec2bcde --- /dev/null +++ b/app/Http/Requests/StoreDepartmentRequest.php @@ -0,0 +1,32 @@ + + */ + public function rules(): array + { + return [ + 'position' => 'required|int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + 'faculty_id' => 'required|int' + ]; + } +} diff --git a/app/Http/Requests/UpdateDepartmentRequest.php b/app/Http/Requests/UpdateDepartmentRequest.php new file mode 100644 index 0000000..eaf23dd --- /dev/null +++ b/app/Http/Requests/UpdateDepartmentRequest.php @@ -0,0 +1,37 @@ +|string> + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'description' => 'string', + 'faculty_id' => 'int|required', + 'name' => [ + 'required', + 'string', + 'max:255', + "unique:educational_institutions,name,{$this->department->id}", + ], + ]; + } +} diff --git a/app/Models/Department.php b/app/Models/Department.php new file mode 100644 index 0000000..f691ec8 --- /dev/null +++ b/app/Models/Department.php @@ -0,0 +1,24 @@ +belongsTo(Faculty::class); + } +} diff --git a/app/Policies/DepartmentPolicy.php b/app/Policies/DepartmentPolicy.php new file mode 100644 index 0000000..e60adbd --- /dev/null +++ b/app/Policies/DepartmentPolicy.php @@ -0,0 +1,66 @@ + + */ +class DepartmentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_02_08_074258_create_departments_table.php b/database/migrations/2024_02_08_074258_create_departments_table.php new file mode 100644 index 0000000..ab751c8 --- /dev/null +++ b/database/migrations/2024_02_08_074258_create_departments_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('description'); + $table->integer('position'); + $table->foreignId('faculty_id')->constrained('faculties'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('departments'); + } +}; diff --git a/database/seeders/DepartmentSeeder.php b/database/seeders/DepartmentSeeder.php new file mode 100644 index 0000000..9828de1 --- /dev/null +++ b/database/seeders/DepartmentSeeder.php @@ -0,0 +1,17 @@ +
- Добавить файл @@ -104,7 +104,7 @@ @php($idReceptionScreen = $receptionScreen->id) - Добавить + Добавить файл diff --git a/resources/views/catalog/department/create.blade.php b/resources/views/catalog/department/create.blade.php new file mode 100644 index 0000000..f06e265 --- /dev/null +++ b/resources/views/catalog/department/create.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin-layout') +@section('content') + + @auth() +
+
+

Создать кафедру

+ {{ Form::open(['url' => route('departments.store'), 'method' => 'POST', 'class' => '']) }} +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::label('faculty_id', 'Факультет') }} +
+
+ {{ Form::select('faculty_id', $faculties, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('faculty_id') }} + @endif +
+
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/catalog/department/index.blade.php b/resources/views/catalog/department/index.blade.php new file mode 100644 index 0000000..b97cf3d --- /dev/null +++ b/resources/views/catalog/department/index.blade.php @@ -0,0 +1,43 @@ +@extends('layouts.admin-layout') +@section('content') +
+

Кафедры

+
+ Создать Кафедру +
+
+ + + + + + + + + + + + + + @foreach($departments as $department) + + + + + + + + @endforeach + +
ПозицияНазваниеОписаниеФакультетдействия
{{ $department->position }}{{ $department->name }}{{ Str::words($department->description, 10, '...') }}{{ $department->faculty->name }} + редактировать + удалить +
+
+
+
+ +@endsection diff --git a/resources/views/catalog/department/show.blade.php b/resources/views/catalog/department/show.blade.php new file mode 100644 index 0000000..18b9a8c --- /dev/null +++ b/resources/views/catalog/department/show.blade.php @@ -0,0 +1,31 @@ +@php + use App\Models\Department; + use App\Models\Faculty; + use Illuminate\Support\Collection; + /** @var Collection|Department[] $department */ + + $faculty = Faculty::find($department->faculty->id) +@endphp +@extends('layouts.admin-layout') +@section('content') + @auth() +
+ + {{ $faculty->educationalInstitution->name }} + -> {{ $faculty->name }} + -> {{ $department->name }} +
+
+

Название

+

{{ $department->name }}

+

Описание

+

{{ $department->description }}

+

Позиция

+

{{ $department->position }}

+ {{--

Факультеты

--}} + {{-- @foreach($department->faculties as $faculty)--}} + {{--

{{ $faculty->name }}

--}} + {{-- @endforeach--}} +
+ @endauth +@endsection diff --git a/routes/admin.php b/routes/admin.php index 8a35292..a5d7611 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -1,13 +1,14 @@ group(function () { - Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('files.create'); + Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('files_create'); Route::get('/files/download/{file}', [FileController::class, 'download'])->name('files.download'); Route::resources([ @@ -16,5 +17,6 @@ Route::middleware(['auth', 'verified'])->group(function () { '/admin-reception-screen' => ReceptionScreenController::class, '/educational-institutions' => EducationalInstitutionController::class, '/faculties' => FacultyController::class, + '/departments' => DepartmentController::class, ]); }); diff --git a/routes/pages/web.php b/routes/pages/web.php index f134b78..94419bc 100644 --- a/routes/pages/web.php +++ b/routes/pages/web.php @@ -71,7 +71,7 @@ Route::get('/general-information', function () { return view('menu.inostrannym-abiturientam.obshchie-svedeniya'); })->name('obshchie-svedeniya'); -Route::get('/departments', function () { +Route::get('/departments-list', function () { return view('menu.inostrannym-abiturientam.kafedry'); })->name('kafedry');