diff --git a/app/Http/Controllers/admin/Catalog/EducationLevelController.php b/app/Http/Controllers/admin/Catalog/EducationLevelController.php new file mode 100644 index 0000000..1b9977f --- /dev/null +++ b/app/Http/Controllers/admin/Catalog/EducationLevelController.php @@ -0,0 +1,75 @@ +validated(); + $level = new EducationLevel(); + $level->name = $validated['name']; + $level->description = $validated['description']; + $level->slug = $validated['slug']; + $level->save(); + + return redirect()->route('education_levels.index'); + } + + public function show( + EducationLevel $educationLevel + ): View|Application|Factory|\Illuminate\Contracts\Foundation\Application + { + $directions = $educationLevel->directions(); + return view( + 'admin.catalog.education_level.show', + compact('educationLevel', 'directions') + ); + } + + public function edit(EducationLevel $educationLevel) + { + return view('admin.catalog.education_level.edit', compact('educationLevel')); + } + + public function update(UpdateEducationLevelRequest $request, EducationLevel $educationLevel): RedirectResponse + { + $validated = $request->validated(); + + $educationLevel->name = $validated['name']; + $educationLevel->description = $validated['description']; + $educationLevel->slug = $validated['slug']; + $educationLevel->save(); + + return redirect()->route('education_levels.index'); + } + + public function destroy(EducationLevel $educationLevel) + { + if($educationLevel->directions()->exists()) { + return back(); + } + $educationLevel->delete(); + return redirect()->route('education_levels.index'); + } +} diff --git a/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php new file mode 100644 index 0000000..171ddf2 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/StoreEducationLevelRequest.php @@ -0,0 +1,22 @@ + 'required|string|max:255|unique:education_levels,name', + 'description' => 'string', + 'slug' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php new file mode 100644 index 0000000..cb1ef35 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/UpdateEducationLevelRequest.php @@ -0,0 +1,22 @@ + "required|string|max:255|unique:education_levels,name,{$this->education_level->id}", + 'description' => 'string', + 'slug' => 'required|string', + ]; + } +} diff --git a/app/Models/EducationLevel.php b/app/Models/EducationLevel.php new file mode 100644 index 0000000..cd879d3 --- /dev/null +++ b/app/Models/EducationLevel.php @@ -0,0 +1,24 @@ +hasMany('App\Models\Direction', 'education_level_id'); + } +} diff --git a/database/factories/EducationLevelFactory.php b/database/factories/EducationLevelFactory.php new file mode 100644 index 0000000..2ab7c66 --- /dev/null +++ b/database/factories/EducationLevelFactory.php @@ -0,0 +1,17 @@ + fake()->name(), + 'description' => fake()->text(), + 'slug' => fake()->slug(), + ]; + } +} diff --git a/database/migrations/2024_02_09_114154_create_education_levels_table.php b/database/migrations/2024_02_09_114154_create_education_levels_table.php new file mode 100644 index 0000000..9d439ff --- /dev/null +++ b/database/migrations/2024_02_09_114154_create_education_levels_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name'); + $table->text('description'); + $table->string('slug'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('education_levels'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6b484d6..4962c10 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -24,6 +24,7 @@ class DatabaseSeeder extends Seeder EducationalInstitutionSeeder::class, FacultySeeder::class, DepartmentSeeder::class, + EducationLevelSeeder::class, DirectionSeeder::class, ]); diff --git a/database/seeders/EducationLevelSeeder.php b/database/seeders/EducationLevelSeeder.php new file mode 100644 index 0000000..454cb54 --- /dev/null +++ b/database/seeders/EducationLevelSeeder.php @@ -0,0 +1,31 @@ +insert([ + [ + 'name' => 'бакалавриат', + 'description' => 'бакалавриат', + 'slug' => 'baccalaureate', + ], + [ + 'name' => 'специалитет', + 'description' => 'специалитет', + 'slug' => 'specialty', + ], + [ + 'name' => 'магитсратура', + 'description' => 'магитсратура', + 'slug' => 'magistracy', + ], + ]); + } +} diff --git a/resources/views/admin/catalog/education_level/create.blade.php b/resources/views/admin/catalog/education_level/create.blade.php new file mode 100644 index 0000000..59a646e --- /dev/null +++ b/resources/views/admin/catalog/education_level/create.blade.php @@ -0,0 +1,52 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
Название | +Описание | +URL | +действия | ++ |
---|---|---|---|---|
{{ $level->name }} | +{{ Str::words($level->description, 10, '...') }} | +{{ $level->slug }} | ++ редактировать + удалить + | +
{{ $educationLevel->name }}
+{{ $educationLevel->description }}
+{{ $educationLevel->slug }}
+