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() +
+
+

Создать Уровень Образования

+ {{ Form::open(['url' => route('education_levels.store'), 'method' => 'POST', 'class' => '']) }} +
+
+ {{ 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('slug', 'URL') }} +
+
+ {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/education_level/edit.blade.php b/resources/views/admin/catalog/education_level/edit.blade.php new file mode 100644 index 0000000..868fcb5 --- /dev/null +++ b/resources/views/admin/catalog/education_level/edit.blade.php @@ -0,0 +1,53 @@ +@extends('layouts.admin_layout') +@section('content') + + @auth() +
+
+

Езменить уровень образования

+ {{ Form::open(['url' => route('education_levels.update', $educationLevel), 'method' => 'PATCH', 'class' => '']) }} +
+
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', $educationLevel->name, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $educationLevel->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', $educationLevel->slug, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/education_level/index.blade.php b/resources/views/admin/catalog/education_level/index.blade.php new file mode 100644 index 0000000..cb1e89a --- /dev/null +++ b/resources/views/admin/catalog/education_level/index.blade.php @@ -0,0 +1,39 @@ +@extends('layouts.admin_layout') +@section('content') +
+

Уровни образования

+
+ Создать Уровень образования +
+
+ + + + + + + + + + + + @foreach($levels as $level) + + + + + + + @endforeach + +
НазваниеОписаниеURLдействия
{{ $level->name }}{{ Str::words($level->description, 10, '...') }}{{ $level->slug }} + редактировать + удалить +
+
+
+
+@endsection diff --git a/resources/views/admin/catalog/education_level/show.blade.php b/resources/views/admin/catalog/education_level/show.blade.php new file mode 100644 index 0000000..13d4cc9 --- /dev/null +++ b/resources/views/admin/catalog/education_level/show.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+

Название

+

{{ $educationLevel->name }}

+

Описание

+

{{ $educationLevel->description }}

+

URL

+

{{ $educationLevel->slug }}

+

Направления

+ @foreach($directions as $direction) +

{{ $direction->name }}

+ @endforeach +
+ @endauth +@endsection diff --git a/resources/views/layouts/admin_layout.blade.php b/resources/views/layouts/admin_layout.blade.php index 767677f..ecde120 100644 --- a/resources/views/layouts/admin_layout.blade.php +++ b/resources/views/layouts/admin_layout.blade.php @@ -56,6 +56,7 @@
  • Факультеты
  • Кафедры
  • Направления
  • +
  • Уровни образования
  • @yield('content')
    diff --git a/routes/admin.php b/routes/admin.php index 6bd4df5..5886bb8 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -4,6 +4,7 @@ use App\Http\Controllers\admin\AdmissionController; use App\Http\Controllers\admin\Catalog\DepartmentController; use App\Http\Controllers\admin\Catalog\DirectionController; use App\Http\Controllers\admin\Catalog\EducationalInstitutionController; +use App\Http\Controllers\admin\Catalog\EducationLevelController; use App\Http\Controllers\admin\Catalog\FacultyController; use App\Http\Controllers\admin\DocumentController; use App\Http\Controllers\admin\UserController; @@ -33,6 +34,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { ->scoped(['faculty' => 'slug']); Route::resource('/admissions', AdmissionController::class); + Route::resource('/education_levels', EducationLevelController::class) + ->scoped(['education_level' => 'slug']); + Route::resources([ '/documents' => DocumentController::class, '/users' => UserController::class,