From 06c16d95c1e3027dff9d7b57f068aa20a7a4a721 Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 7 Feb 2024 10:18:46 +0300 Subject: [PATCH] add EducationalInstitution resource --- .../EducationalInstitutionController.php | 66 +++++++++++++++++++ .../StoreEducationalInstitutionRequest.php | 30 +++++++++ .../UpdateEducationalInstitutionRequest.php | 30 +++++++++ app/Models/EducationalInstitution.php | 11 ++++ app/Policies/EducationalInstitutionPolicy.php | 66 +++++++++++++++++++ .../EducationalInstitutionFactory.php | 23 +++++++ ..._create_educational_institutions_table.php | 30 +++++++++ database/seeders/DatabaseSeeder.php | 4 +- .../seeders/EducationalInstitutionSeeder.php | 17 +++++ .../educational-institution/create.blade.php | 53 +++++++++++++++ .../educational-institution/edit.blade.php | 53 +++++++++++++++ .../educational-institution/index.blade.php | 42 ++++++++++++ .../views/layouts/admin-layout.blade.php | 1 + routes/web.php | 2 + 14 files changed, 426 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/EducationalInstitutionController.php create mode 100644 app/Http/Requests/StoreEducationalInstitutionRequest.php create mode 100644 app/Http/Requests/UpdateEducationalInstitutionRequest.php create mode 100644 app/Models/EducationalInstitution.php create mode 100644 app/Policies/EducationalInstitutionPolicy.php create mode 100644 database/factories/EducationalInstitutionFactory.php create mode 100644 database/migrations/2024_02_06_062744_create_educational_institutions_table.php create mode 100644 database/seeders/EducationalInstitutionSeeder.php create mode 100644 resources/views/educational-institution/create.blade.php create mode 100644 resources/views/educational-institution/edit.blade.php create mode 100644 resources/views/educational-institution/index.blade.php diff --git a/app/Http/Controllers/EducationalInstitutionController.php b/app/Http/Controllers/EducationalInstitutionController.php new file mode 100644 index 0000000..db2a7ac --- /dev/null +++ b/app/Http/Controllers/EducationalInstitutionController.php @@ -0,0 +1,66 @@ +validated(); + + $educationalInstitution = new EducationalInstitution(); + $educationalInstitution->name = $validated['name']; + $educationalInstitution->description = $validated['description']; + $educationalInstitution->position = $validated['position']; + $educationalInstitution->save(); + + return redirect()->route('educational-institutions.index'); + } + + public function show(EducationalInstitution $educationalInstitution) + { + return view('educational-institution.show', compact('educationalInstitution')); + } + + public function edit(EducationalInstitution $educationalInstitution) + { + return view('educational-institution.edit', compact('educationalInstitution')); + } + + public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution) + { + $validated = $request->validated(); + + $educationalInstitution->name = $validated['name']; + $educationalInstitution->description = $validated['description']; + $educationalInstitution->position = $validated['position']; + $educationalInstitution->save(); + + return redirect()->route('educational-institutions.index'); + } + + public function destroy(EducationalInstitution $educationalInstitution) + { + $educationalInstitution->delete(); + + return redirect()->route('educational-institutions.index'); + } +} diff --git a/app/Http/Requests/StoreEducationalInstitutionRequest.php b/app/Http/Requests/StoreEducationalInstitutionRequest.php new file mode 100644 index 0000000..8974bb5 --- /dev/null +++ b/app/Http/Requests/StoreEducationalInstitutionRequest.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + ]; + } +} diff --git a/app/Http/Requests/UpdateEducationalInstitutionRequest.php b/app/Http/Requests/UpdateEducationalInstitutionRequest.php new file mode 100644 index 0000000..0af247b --- /dev/null +++ b/app/Http/Requests/UpdateEducationalInstitutionRequest.php @@ -0,0 +1,30 @@ +|string> + */ + public function rules(): array + { + return [ + 'position' => 'int|max:255', + 'name' => 'required|string|max:255|unique:educational_institutions,name', + 'description' => 'string', + ]; + } +} diff --git a/app/Models/EducationalInstitution.php b/app/Models/EducationalInstitution.php new file mode 100644 index 0000000..d7616a5 --- /dev/null +++ b/app/Models/EducationalInstitution.php @@ -0,0 +1,11 @@ + + */ +class EducationalInstitutionFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + // + ]; + } +} diff --git a/database/migrations/2024_02_06_062744_create_educational_institutions_table.php b/database/migrations/2024_02_06_062744_create_educational_institutions_table.php new file mode 100644 index 0000000..84a89dd --- /dev/null +++ b/database/migrations/2024_02_06_062744_create_educational_institutions_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name'); + $table->text('description'); + $table->integer('position'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('educational_institutions'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index c7ffdf3..b2e7bda 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -13,8 +13,8 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - User::factory(10)->create(); - +// User::factory(10)->create(); +// User::factory()->create([ 'name' => 'admin', 'email' => 'test@example.com', diff --git a/database/seeders/EducationalInstitutionSeeder.php b/database/seeders/EducationalInstitutionSeeder.php new file mode 100644 index 0000000..d2ed4c2 --- /dev/null +++ b/database/seeders/EducationalInstitutionSeeder.php @@ -0,0 +1,17 @@ + +
+

Создать учебное заведение

+ {{ Form::open(['url' => route('educational-institutions.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::submit('создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+ + @endauth +@endsection diff --git a/resources/views/educational-institution/edit.blade.php b/resources/views/educational-institution/edit.blade.php new file mode 100644 index 0000000..4aa682b --- /dev/null +++ b/resources/views/educational-institution/edit.blade.php @@ -0,0 +1,53 @@ +@extends('layouts.admin-layout') +@section('content') + + @auth() +
+
+

Изменить учебное заведение

+ {{ Form::open(['url' => route('educational-institutions.update', $educationalInstitution), 'method' => 'PATCH', 'class' => '']) }} +
+
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $educationalInstitution->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', $educationalInstitution->name, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $educationalInstitution->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/educational-institution/index.blade.php b/resources/views/educational-institution/index.blade.php new file mode 100644 index 0000000..522941c --- /dev/null +++ b/resources/views/educational-institution/index.blade.php @@ -0,0 +1,42 @@ +@extends('layouts.admin-layout') +@section('content') +
+

Учебные заведения

+
+ Создать учебное заведение +
+
+ + + + + + + + + + + + + @foreach($educationalInstitutions as $educationalInstitution) + + + + + + + @endforeach + +
ПозицияНазваниеОписаниедействия
{{ $educationalInstitution->position }}{{ $educationalInstitution->name }}{{ $educationalInstitution->description }}редактировать + + удалить + +
+
+
+
+ +@endsection diff --git a/resources/views/layouts/admin-layout.blade.php b/resources/views/layouts/admin-layout.blade.php index 2275618..d89a2e4 100644 --- a/resources/views/layouts/admin-layout.blade.php +++ b/resources/views/layouts/admin-layout.blade.php @@ -54,6 +54,7 @@ @if(!is_null(Auth::getUser()) && Auth::getUser()->name === 'admin') {{--
  • --}}
  • Список администраторов
  • +
  • Учебные заведения
  • @endif diff --git a/routes/web.php b/routes/web.php index 290e74b..4244c88 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ middleware(['auth', 'verified']); Route::resource('/admin-reception-screen', ReceptionScreenController::class)->middleware(['auth', 'verified']); +Route::resource('/educational-institutions', EducationalInstitutionController::class)->middleware(['auth', 'verified']); Route::get('/files', [FileController::class, 'index'])->name('files.index'); Route::post('/files', [FileController::class, 'store'])->name('files.store'); Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('files.create');