From 1670434c8c5785792646fa724a6600a39f002894 Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 7 Feb 2024 16:30:49 +0300 Subject: [PATCH] add Faculty resource --- app/Http/Controllers/FacultyController.php | 66 +++++++++++++++++++ app/Http/Requests/StoreFacultyRequest.php | 29 ++++++++ app/Http/Requests/UpdateFacultyRequest.php | 31 +++++++++ app/Models/Faculty.php | 24 +++++++ app/Policies/FacultyPolicy.php | 66 +++++++++++++++++++ database/factories/FacultyFactory.php | 23 +++++++ ...24_02_07_073254_create_faculties_table.php | 31 +++++++++ database/seeders/FacultySeeder.php | 17 +++++ qodana.yaml | 32 +++++++++ .../views/catalog/faculty/create.blade.php | 64 ++++++++++++++++++ .../views/catalog/faculty/edit.blade.php | 64 ++++++++++++++++++ .../views/catalog/faculty/index.blade.php | 44 +++++++++++++ 12 files changed, 491 insertions(+) create mode 100644 app/Http/Controllers/FacultyController.php create mode 100644 app/Http/Requests/StoreFacultyRequest.php create mode 100644 app/Http/Requests/UpdateFacultyRequest.php create mode 100644 app/Models/Faculty.php create mode 100644 app/Policies/FacultyPolicy.php create mode 100644 database/factories/FacultyFactory.php create mode 100644 database/migrations/2024_02_07_073254_create_faculties_table.php create mode 100644 database/seeders/FacultySeeder.php create mode 100644 qodana.yaml create mode 100644 resources/views/catalog/faculty/create.blade.php create mode 100644 resources/views/catalog/faculty/edit.blade.php create mode 100644 resources/views/catalog/faculty/index.blade.php diff --git a/app/Http/Controllers/FacultyController.php b/app/Http/Controllers/FacultyController.php new file mode 100644 index 0000000..43151fb --- /dev/null +++ b/app/Http/Controllers/FacultyController.php @@ -0,0 +1,66 @@ +validated(); + + $faculty = new Faculty(); + $faculty->name = $validated['name']; + $faculty->description = $validated['description']; + $faculty->position = $validated['position']; + $faculty->educational_institution_id = $validated['educational_institution_id']; + $faculty->save(); + + return redirect()->route('faculties.index'); + } + + public function edit(Faculty $faculty) + { + $educationalInstitutions = EducationalInstitution::pluck('name', 'id'); + return view('catalog.faculty.edit', compact('faculty', 'educationalInstitutions')); + } + + public function update(UpdateFacultyRequest $request, Faculty $faculty) + { + $validated = $request->validated(); + + $faculty->name = $validated['name']; + $faculty->description = $validated['description']; + $faculty->position = $validated['position']; + $faculty->educational_institution_id = $validated['educational_institution_id']; + $faculty->save(); + + return redirect()->route('faculties.index'); + } + + public function destroy(Faculty $faculty) + { + $faculty->delete(); + return redirect()->route('faculties.index'); + } +} diff --git a/app/Http/Requests/StoreFacultyRequest.php b/app/Http/Requests/StoreFacultyRequest.php new file mode 100644 index 0000000..e274fe2 --- /dev/null +++ b/app/Http/Requests/StoreFacultyRequest.php @@ -0,0 +1,29 @@ + + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + 'educational_institution_id' => 'int' + ]; + } +} diff --git a/app/Http/Requests/UpdateFacultyRequest.php b/app/Http/Requests/UpdateFacultyRequest.php new file mode 100644 index 0000000..40b4f06 --- /dev/null +++ b/app/Http/Requests/UpdateFacultyRequest.php @@ -0,0 +1,31 @@ +|string> + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + 'educational_institution_id' => 'int' + ]; + } +} diff --git a/app/Models/Faculty.php b/app/Models/Faculty.php new file mode 100644 index 0000000..5568657 --- /dev/null +++ b/app/Models/Faculty.php @@ -0,0 +1,24 @@ +belongsTo(EducationalInstitution::class); + } +} diff --git a/app/Policies/FacultyPolicy.php b/app/Policies/FacultyPolicy.php new file mode 100644 index 0000000..2f2623c --- /dev/null +++ b/app/Policies/FacultyPolicy.php @@ -0,0 +1,66 @@ + + */ +class FacultyFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_02_07_073254_create_faculties_table.php b/database/migrations/2024_02_07_073254_create_faculties_table.php new file mode 100644 index 0000000..eefb309 --- /dev/null +++ b/database/migrations/2024_02_07_073254_create_faculties_table.php @@ -0,0 +1,31 @@ +id(); + $table->string('name'); + $table->string('description'); + $table->integer('position'); + $table->foreignId('educational_institution_id')->constrained('educational_institutions'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('faculties'); + } +}; diff --git a/database/seeders/FacultySeeder.php b/database/seeders/FacultySeeder.php new file mode 100644 index 0000000..d1deff0 --- /dev/null +++ b/database/seeders/FacultySeeder.php @@ -0,0 +1,17 @@ + + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +php: + version: 8.3 #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-php:latest diff --git a/resources/views/catalog/faculty/create.blade.php b/resources/views/catalog/faculty/create.blade.php new file mode 100644 index 0000000..66a44b6 --- /dev/null +++ b/resources/views/catalog/faculty/create.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin-layout') +@section('content') + + @auth() +
+
+

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

+ {{ Form::open(['url' => route('faculties.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('educational_institution_id', 'Учебное заведение') }} +
+
+ {{ Form::select('educational_institution_id', $educationalInstitutions, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('educational_institution_id') }} + @endif +
+
+ {{ Form::submit('создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/catalog/faculty/edit.blade.php b/resources/views/catalog/faculty/edit.blade.php new file mode 100644 index 0000000..085620d --- /dev/null +++ b/resources/views/catalog/faculty/edit.blade.php @@ -0,0 +1,64 @@ +@extends('layouts.admin-layout') +@section('content') + + @auth() +
+
+

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

+ {{ Form::open(['url' => route('faculties.update', $faculty), 'method' => 'PATCH', 'class' => '']) }} +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $faculty->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', $faculty->name, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $faculty->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::label('educational_institution_id', 'Учебное заведение') }} +
+
+ {{ Form::select('educational_institution_id', $educationalInstitutions, $faculty->educationalInstitution->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('educational_institution_id') }} + @endif +
+
+ {{ Form::submit('создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/catalog/faculty/index.blade.php b/resources/views/catalog/faculty/index.blade.php new file mode 100644 index 0000000..8ccea3c --- /dev/null +++ b/resources/views/catalog/faculty/index.blade.php @@ -0,0 +1,44 @@ +@extends('layouts.admin-layout') +@section('content') +
+

Факультеты

+
+ Создать Факультет +
+
+ + + + + + + + + + + + + + @foreach($faculties as $faculty) + + + + + + + + @endforeach + +
ПозицияНазваниеОписаниеУчебное заведениедействия
{{ $faculty->position }}{{ $faculty->name }}{{ $faculty->description }}{{ $faculty->educationalInstitution->name }}редактировать + + удалить + +
+
+
+
+ +@endsection