diff --git a/app/Http/Controllers/admin/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php
index 9d39d43..0672c4a 100644
--- a/app/Http/Controllers/admin/Catalog/DirectionController.php
+++ b/app/Http/Controllers/admin/Catalog/DirectionController.php
@@ -7,6 +7,7 @@ use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
use App\Models\Department;
use App\Models\Direction;
+use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use Illuminate\Contracts\View\Factory;
@@ -25,8 +26,9 @@ class DirectionController extends Controller
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$levels = EducationLevel::pluck('name', 'id');
+ $forms = EducationForm::pluck('name', 'id');
$departments = Department::pluck('name', 'id');
- return view('admin.catalog.direction.create', compact('departments', 'levels'));
+ return view('admin.catalog.direction.create', compact('departments', 'levels', 'forms'));
}
public function store(StoreDirectionRequest $request): RedirectResponse
@@ -40,6 +42,7 @@ class DirectionController extends Controller
$direction->slug = $validated['slug'];
$direction->code = $validated['code'];
$direction->education_level_id = $validated['education_level_id'];
+ $direction->education_form_id = $validated['education_form_id'];
$direction->department_id = $validated['department_id'];
$direction->save();
@@ -66,7 +69,8 @@ class DirectionController extends Controller
{
$levels = EducationLevel::pluck('name', 'id');
$departments = Department::pluck('name', 'id');
- return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels'));
+ $forms = EducationForm::pluck('name', 'id');
+ return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels', 'forms'));
}
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
@@ -80,6 +84,7 @@ class DirectionController extends Controller
$direction->slug = $validated['slug'];
$direction->code = $validated['code'];
$direction->education_level_id = $validated['education_level_id'];
+ $direction->education_form_id = $validated['education_form_id'];
$direction->department_id = $validated['department_id'];
$direction->save();
diff --git a/app/Http/Controllers/admin/Catalog/EducationFormController.php b/app/Http/Controllers/admin/Catalog/EducationFormController.php
new file mode 100644
index 0000000..8cd1e08
--- /dev/null
+++ b/app/Http/Controllers/admin/Catalog/EducationFormController.php
@@ -0,0 +1,69 @@
+validated();
+ $form = new EducationForm();
+ $form->name = $validated['name'];
+ $form->description = $validated['description'];
+ $form->slug = $validated['slug'];
+ $form->save();
+
+ return redirect()->route('education_forms.index');
+ }
+
+ public function show(EducationForm $educationForm): View|Factory|\Illuminate\Contracts\Foundation\Application
+ {
+ $directions = $educationForm->directions;
+ return view('admin.catalog.education_form.show', compact('educationForm', 'directions'));
+ }
+
+ public function edit(EducationForm $educationForm)
+ {
+ return view('admin.catalog.education_form.edit', compact('educationForm'));
+ }
+
+ public function update(UpdateEducationFormRequest $request, EducationForm $educationForm)
+ {
+ $validated = $request->validated();
+
+ $educationForm->name = $validated['name'];
+ $educationForm->description = $validated['description'];
+ $educationForm->slug = $validated['slug'];
+ $educationForm->save();
+
+ return redirect()->route('education_forms.index');
+ }
+
+ public function destroy(EducationForm $educationForm)
+ {
+ if ($educationForm->directions()->exists()) {
+ return back();
+ }
+ $educationForm->delete();
+ return redirect()->route('education_forms.index');
+ }
+}
diff --git a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php
index 7b46e17..d5f190f 100644
--- a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php
+++ b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php
@@ -20,6 +20,7 @@ class StoreDirectionRequest extends FormRequest
'slug' => 'required|string|max:255',
'code' => 'required|string|max:255',
'education_level_id' => 'required|int|numeric|max:1000',
+ 'education_form_id' => 'required|int|numeric|max:1000',
'department_id' => 'required|numeric|int|max:1000'
];
}
diff --git a/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php b/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php
new file mode 100644
index 0000000..d5a553f
--- /dev/null
+++ b/app/Http/Requests/admin/Catalog/StoreEducationFormRequest.php
@@ -0,0 +1,22 @@
+ 'required|string|max:255|unique:education_levels,name',
+ 'description' => 'string',
+ 'slug' => 'required|string|max:255',
+ ];
+ }
+}
diff --git a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php
index 1e2c8a0..c8f4bd5 100644
--- a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php
+++ b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php
@@ -21,6 +21,7 @@ class UpdateDirectionRequest extends FormRequest
'slug' => 'required|string|max:255',
'code' => 'required|string|max:255',
'education_level_id' => 'required|int|numeric|max:1000',
+ 'education_form_id' => 'required|int|numeric|max:1000',
'name' => [
'required',
'string',
diff --git a/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php b/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php
new file mode 100644
index 0000000..61a2092
--- /dev/null
+++ b/app/Http/Requests/admin/Catalog/UpdateEducationFormRequest.php
@@ -0,0 +1,22 @@
+ "required|string|max:255|unique:education_forms,name,{$this->education_form->id}",
+ 'description' => 'string',
+ 'slug' => 'required|string|max:255',
+ ];
+ }
+}
diff --git a/app/Models/Direction.php b/app/Models/Direction.php
index db3ebc3..34df08c 100644
--- a/app/Models/Direction.php
+++ b/app/Models/Direction.php
@@ -28,4 +28,9 @@ class Direction extends Model
{
return $this->belongsTo(EducationLevel::class);
}
+
+ public function educationForm(): BelongsTo
+ {
+ return $this->belongsTo(EducationForm::class);
+ }
}
diff --git a/app/Models/EducationForm.php b/app/Models/EducationForm.php
new file mode 100644
index 0000000..94bb1f6
--- /dev/null
+++ b/app/Models/EducationForm.php
@@ -0,0 +1,24 @@
+hasMany('App\Models\Direction', 'education_form_id');
+ }
+}
diff --git a/database/factories/DirectionFactory.php b/database/factories/DirectionFactory.php
index c1143c8..a66584a 100644
--- a/database/factories/DirectionFactory.php
+++ b/database/factories/DirectionFactory.php
@@ -15,7 +15,8 @@ class DirectionFactory extends Factory
'code' => fake()->text(50),
'position' => fake()->randomDigit(),
'department_id' => 1,
- 'education_level_id' => 1
+ 'education_level_id' => 1,
+ 'education_form_id' => 1,
];
}
}
diff --git a/database/factories/EducationFormFactory.php b/database/factories/EducationFormFactory.php
new file mode 100644
index 0000000..fb86d70
--- /dev/null
+++ b/database/factories/EducationFormFactory.php
@@ -0,0 +1,17 @@
+ fake()->name(),
+ 'description' => fake()->text(),
+ 'slug' => fake()->slug(),
+ ];
+ }
+}
diff --git a/database/migrations/2024_02_09_114155_create_directions_table.php b/database/migrations/2024_02_09_114155_create_directions_table.php
index 3a7c9cd..63d2318 100644
--- a/database/migrations/2024_02_09_114155_create_directions_table.php
+++ b/database/migrations/2024_02_09_114155_create_directions_table.php
@@ -17,6 +17,7 @@ return new class extends Migration
$table->string('slug');
$table->foreignId('department_id')->constrained('departments');
$table->foreignId('education_level_id')->constrained('education_levels');
+ $table->foreignId('education_form_id')->constrained('education_forms');
$table->timestamps();
});
}
diff --git a/database/migrations/2024_02_14_135058_create_education_forms_table.php b/database/migrations/2024_02_14_135058_create_education_forms_table.php
new file mode 100644
index 0000000..f5911b5
--- /dev/null
+++ b/database/migrations/2024_02_14_135058_create_education_forms_table.php
@@ -0,0 +1,24 @@
+id();
+ $table->string('name');
+ $table->text('description')->nullable();
+ $table->string('slug');
+ $table->timestamps();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::dropIfExists('education_forms');
+ }
+};
diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php
index 4962c10..e33cb85 100644
--- a/database/seeders/DatabaseSeeder.php
+++ b/database/seeders/DatabaseSeeder.php
@@ -25,6 +25,7 @@ class DatabaseSeeder extends Seeder
FacultySeeder::class,
DepartmentSeeder::class,
EducationLevelSeeder::class,
+ EducationFormSeeder::class,
DirectionSeeder::class,
]);
diff --git a/database/seeders/DirectionSeeder.php b/database/seeders/DirectionSeeder.php
index adf9119..7938a5a 100644
--- a/database/seeders/DirectionSeeder.php
+++ b/database/seeders/DirectionSeeder.php
@@ -19,6 +19,7 @@ class DirectionSeeder extends Seeder
'position' => 1,
'department_id' => 1,
'education_level_id' => 1,
+ 'education_form_id' => 1,
],
[
'name' => 'фармация',
@@ -28,6 +29,7 @@ class DirectionSeeder extends Seeder
'position' => 2,
'department_id' => 1,
'education_level_id' => 2,
+ 'education_form_id' => 2,
],
[
'name' => 'строительство',
@@ -37,6 +39,7 @@ class DirectionSeeder extends Seeder
'position' => 3,
'department_id' => 1,
'education_level_id' => 3,
+ 'education_form_id' => 3,
],
]);
}
diff --git a/database/seeders/EducationFormSeeder.php b/database/seeders/EducationFormSeeder.php
new file mode 100644
index 0000000..28d6a4f
--- /dev/null
+++ b/database/seeders/EducationFormSeeder.php
@@ -0,0 +1,31 @@
+insert([
+ [
+ 'name' => 'очная',
+ 'description' => 'очная',
+ 'slug' => 'full-time',
+ ],
+ [
+ 'name' => 'заочная',
+ 'description' => 'специалитет',
+ 'slug' => 'part-time',
+ ],
+ [
+ 'name' => 'очно-заочная',
+ 'description' => 'очно-заочная',
+ 'slug' => 'blended',
+ ],
+ ]);
+ }
+}
diff --git a/resources/views/admin/catalog/direction/create.blade.php b/resources/views/admin/catalog/direction/create.blade.php
index 0f41774..e14aa6c 100644
--- a/resources/views/admin/catalog/direction/create.blade.php
+++ b/resources/views/admin/catalog/direction/create.blade.php
@@ -65,6 +65,18 @@
@endif
+
+ {{ Form::label('education_form_id', 'Увовень образования') }}
+
+
+ {{ Form::select('education_form_id', $forms, null, ['class' => 'form-select']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('education_form_id') }}
+ @endif
+
+
{{ Form::label('slug', 'URL') }}
diff --git a/resources/views/admin/catalog/direction/edit.blade.php b/resources/views/admin/catalog/direction/edit.blade.php
index ceb27e8..53fd77c 100644
--- a/resources/views/admin/catalog/direction/edit.blade.php
+++ b/resources/views/admin/catalog/direction/edit.blade.php
@@ -66,6 +66,18 @@
@endif
+
+ {{ Form::label('education_form_id', 'Увовень образования') }}
+
+
+ {{ Form::select('education_form_id', $forms, $direction->educationForm->id, ['class' => 'form-select']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('education_form_id') }}
+ @endif
+
+
{{ Form::label('slug', 'URL') }}
diff --git a/resources/views/admin/catalog/education_form/create.blade.php b/resources/views/admin/catalog/education_form/create.blade.php
new file mode 100644
index 0000000..074fd85
--- /dev/null
+++ b/resources/views/admin/catalog/education_form/create.blade.php
@@ -0,0 +1,52 @@
+@extends('layouts.admin_layout')
+@section('content')
+ @auth()
+
+
+
Создать форму Образования
+ {{ Form::open(['url' => route('education_forms.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_form/edit.blade.php b/resources/views/admin/catalog/education_form/edit.blade.php
new file mode 100644
index 0000000..bbac7cc
--- /dev/null
+++ b/resources/views/admin/catalog/education_form/edit.blade.php
@@ -0,0 +1,53 @@
+@extends('layouts.admin_layout')
+@section('content')
+
+ @auth()
+
+
+
Изменить форму образования
+ {{ Form::open(['url' => route('education_forms.update', $educationForm), 'method' => 'PATCH', 'class' => '']) }}
+
+
+ {{ Form::label('name', 'Название') }}
+
+
+ {{ Form::text('name', $educationForm->name, ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('name') }}
+ @endif
+
+
+
+ {{ Form::label('description', 'Описание') }}
+
+
+ {{ Form::text('description', $educationForm->description, ['class' => 'form-control']) }}
+
+
+ @if ($errors->any())
+ {{ $errors->first('description') }}
+ @endif
+
+
+
+ {{ Form::label('slug', 'URL') }}
+
+
+ {{ Form::text('slug', $educationForm->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_form/index.blade.php b/resources/views/admin/catalog/education_form/index.blade.php
new file mode 100644
index 0000000..e129d12
--- /dev/null
+++ b/resources/views/admin/catalog/education_form/index.blade.php
@@ -0,0 +1,39 @@
+@extends('layouts.admin_layout')
+@section('content')
+
+@endsection
diff --git a/resources/views/admin/catalog/education_form/show.blade.php b/resources/views/admin/catalog/education_form/show.blade.php
new file mode 100644
index 0000000..fa351f0
--- /dev/null
+++ b/resources/views/admin/catalog/education_form/show.blade.php
@@ -0,0 +1,17 @@
+@extends('layouts.admin_layout')
+@section('content')
+ @auth()
+
+
Название
+
{{ $educationForm->name }}
+
Описание
+
{{ $educationForm->description }}
+
URL
+
{{ $educationForm->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 ecde120..d8a6c53 100644
--- a/resources/views/layouts/admin_layout.blade.php
+++ b/resources/views/layouts/admin_layout.blade.php
@@ -57,6 +57,7 @@
Кафедры
Направления
Уровни образования
+ Формы образования
@yield('content')
diff --git a/routes/admin.php b/routes/admin.php
index 5886bb8..9ba1f00 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\EducationFormController;
use App\Http\Controllers\admin\Catalog\EducationLevelController;
use App\Http\Controllers\admin\Catalog\FacultyController;
use App\Http\Controllers\admin\DocumentController;
@@ -37,6 +38,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
Route::resource('/education_levels', EducationLevelController::class)
->scoped(['education_level' => 'slug']);
+ Route::resource('/education_forms', EducationFormController::class)
+ ->scoped(['education_form' => 'slug']);
+
Route::resources([
'/documents' => DocumentController::class,
'/users' => UserController::class,
diff --git a/tests/Feature/admin/catalog/DepartmentTest.php b/tests/Feature/admin/catalog/DepartmentTest.php
index 7a9fbd5..efc9efc 100644
--- a/tests/Feature/admin/catalog/DepartmentTest.php
+++ b/tests/Feature/admin/catalog/DepartmentTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
+use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\User;
@@ -21,6 +22,7 @@ class DepartmentTest extends TestCase
EducationalInstitution::factory()->create();
Faculty::factory()->create();
EducationLevel::factory()->create();
+ EducationForm::factory()->create();
$this->department = Department::factory()->create();
$this->data = Department::factory()->make()->only([
diff --git a/tests/Feature/admin/catalog/DirectionTest.php b/tests/Feature/admin/catalog/DirectionTest.php
index 791d329..cd5425e 100644
--- a/tests/Feature/admin/catalog/DirectionTest.php
+++ b/tests/Feature/admin/catalog/DirectionTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
+use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\User;
@@ -22,6 +23,7 @@ class DirectionTest extends TestCase
Faculty::factory()->create();
Department::factory()->create();
EducationLevel::factory()->create();
+ EducationForm::factory()->create();
$this->direction = Direction::factory()->create();
$this->data = Direction::factory()->make()->only([
@@ -31,6 +33,7 @@ class DirectionTest extends TestCase
'code',
'slug',
'education_level_id',
+ 'education_form_id',
'department_id',
]);
diff --git a/tests/Feature/admin/catalog/EducationFormTest.php b/tests/Feature/admin/catalog/EducationFormTest.php
new file mode 100644
index 0000000..c62efcc
--- /dev/null
+++ b/tests/Feature/admin/catalog/EducationFormTest.php
@@ -0,0 +1,123 @@
+create();
+ Faculty::factory()->create();
+ Department::factory()->create();
+ EducationLevel::factory()->create();
+ $this->form = EducationForm::factory()->create();
+
+ $this->direction = Direction::factory()->create();
+ $this->data = EducationForm::factory()->make()->only([
+ 'name',
+ 'description',
+ 'slug',
+ ]);
+
+ $this->user = User::factory()->create([
+ 'name' => 'admin',
+ 'email' => 'test@example.com',
+ 'password' => 123456
+ ]);
+ }
+
+ public function testIndexEducationFormsPage(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->get(route('education_forms.index'));
+
+ $response->assertOk();
+ }
+
+ public function testCreateEducationFormPage(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->get(route('education_forms.create'));
+
+ $response->assertOk();
+ }
+
+ public function testStoreEducationForm(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->post(route('education_forms.store', $this->data));
+
+ $response->assertRedirect(route('education_forms.index'));
+
+ $this->assertDatabaseHas('education_forms', $this->data);
+ }
+
+ public function testShowEducationFormPage(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->get(route('education_forms.show', $this->form));
+
+ $response->assertOk();
+ }
+
+ public function testEditEducationFormPage(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->get(route('education_forms.edit', $this->form));
+
+ $response->assertOk();
+ }
+
+ public function testUpdateEducationForm(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->patch(route('education_forms.update', $this->form), $this->data);
+
+ $response->assertRedirect(route('education_forms.index'));
+
+ $this->assertDatabaseHas('education_forms', $this->data);
+ }
+
+ public function testDestroyEducationForm(): void
+ {
+ $this->direction->delete();
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->delete(route('education_forms.destroy', $this->form));
+
+ $response->assertRedirect(route('education_forms.index'));
+
+ $this->assertDatabaseMissing('education_forms', $this->form->toArray());
+ }
+
+ public function testNotDestroyEducationForm(): void
+ {
+ $response = $this->actingAs($this->user)
+ ->withSession(['banned' => false])
+ ->delete(route('education_forms.destroy', $this->form));
+
+ $response->assertStatus(302);
+
+ $this->assertDatabaseHas('education_forms', $this->form->only(['name', 'slug']));
+ }
+}
diff --git a/tests/Feature/admin/catalog/EducationLevelTest.php b/tests/Feature/admin/catalog/EducationLevelTest.php
index 4d5ecb5..5cdaedc 100644
--- a/tests/Feature/admin/catalog/EducationLevelTest.php
+++ b/tests/Feature/admin/catalog/EducationLevelTest.php
@@ -5,6 +5,7 @@ namespace Tests\Feature\admin\catalog;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EducationalInstitution;
+use App\Models\EducationForm;
use App\Models\EducationLevel;
use App\Models\Faculty;
use App\Models\User;
@@ -22,6 +23,7 @@ class EducationLevelTest extends TestCase
EducationalInstitution::factory()->create();
Faculty::factory()->create();
Department::factory()->create();
+ EducationForm::factory()->create();
$this->level = EducationLevel::factory()->create();
$this->direction = Direction::factory()->create();