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');