diff --git a/app/Http/Controllers/admin/Catalog/Direction/PeriodController.php b/app/Http/Controllers/admin/Catalog/Direction/PeriodController.php new file mode 100644 index 0000000..645e1cd --- /dev/null +++ b/app/Http/Controllers/admin/Catalog/Direction/PeriodController.php @@ -0,0 +1,90 @@ +validated(); + + $period = new Period(); + $period->position = $validated['position']; + $period->description = $validated['description']; + $period->period = $validated['period']; + $period->education_form_id = $validated['education_form_id']; + $period->direction_id = $validated['direction_id']; + $period->save(); + + return redirect()->route('periods.index'); + } + + public function show(Period $period): View + { + return view('admin.catalog.direction.period.show', compact('period')); + } + + public function edit(Period $period): View + { + $directions = Direction::pluck('name', 'id'); + $educationForms = EducationForm::pluck('name', 'id'); + return view( + 'admin.catalog.direction.period.edit', + compact( + 'period', + 'directions', + 'educationForms', + ) + ); + } + + public function update(UpdatePeriodRequest $request, Period $period): RedirectResponse + { + $validated = $request->validated(); + + $period->position = $validated['position']; + $period->description = $validated['description']; + $period->period = $validated['period']; + $period->education_form_id = $validated['education_form_id']; + $period->direction_id = $validated['direction_id']; + $period->save(); + + return redirect()->route('periods.index'); + } + + public function destroy(Period $period): RedirectResponse + { + $period->delete(); + return redirect()->route('periods.index'); + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/StorePeriodRequest.php b/app/Http/Requests/admin/Catalog/Direction/StorePeriodRequest.php new file mode 100644 index 0000000..f3a28ba --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/StorePeriodRequest.php @@ -0,0 +1,24 @@ + 'required|int|numeric|max:255', + 'description' => 'string', + 'period' => 'required|int|numeric|max:10', + 'education_form_id' => 'required|int|numeric|max:255', + 'direction_id' => 'required|int|numeric|max:255', + ]; + } +} diff --git a/app/Http/Requests/admin/Catalog/Direction/UpdatePeriodRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdatePeriodRequest.php new file mode 100644 index 0000000..85b6331 --- /dev/null +++ b/app/Http/Requests/admin/Catalog/Direction/UpdatePeriodRequest.php @@ -0,0 +1,24 @@ + 'required|int|numeric|max:255', + 'description' => 'string', + 'period' => 'required|int|numeric|max:10', + 'education_form_id' => 'required|int|numeric|max:255', + 'direction_id' => 'required|int|numeric|max:255', + ]; + } +} diff --git a/app/Models/Period.php b/app/Models/Period.php new file mode 100644 index 0000000..9372854 --- /dev/null +++ b/app/Models/Period.php @@ -0,0 +1,32 @@ +belongsTo(Direction::class); + } + + public function educationForm(): BelongsTo + { + return $this->belongsTo(EducationForm::class); + } +} diff --git a/database/factories/PeriodFactory.php b/database/factories/PeriodFactory.php new file mode 100644 index 0000000..325b7a6 --- /dev/null +++ b/database/factories/PeriodFactory.php @@ -0,0 +1,19 @@ + 1, + 'description' => fake()->text(), + 'period' => fake()->randomDigit(), + 'education_form_id' => 1, + 'direction_id' => 1, + ]; + } +} diff --git a/database/migrations/2024_02_26_080134_create_periods_table.php b/database/migrations/2024_02_26_080134_create_periods_table.php new file mode 100644 index 0000000..008bafe --- /dev/null +++ b/database/migrations/2024_02_26_080134_create_periods_table.php @@ -0,0 +1,32 @@ +id(); + $table->integer('position'); + $table->integer('period'); + $table->foreignId('education_form_id')->constrained('education_forms'); + $table->foreignId('direction_id')->constrained('directions'); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('periods'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 2b8fb9c..55f581a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -36,6 +36,7 @@ class DatabaseSeeder extends Seeder PlaceSeeder::class, CostSeeder::class, DirectionProfileSeeder::class, + PeriodSeeder::class, ]); $this->call([ diff --git a/database/seeders/PeriodSeeder.php b/database/seeders/PeriodSeeder.php new file mode 100644 index 0000000..e6290ab --- /dev/null +++ b/database/seeders/PeriodSeeder.php @@ -0,0 +1,30 @@ +insert([ + [ + 'position' => 1, + 'period' => 4.5, + 'education_form_id' => 1, + 'direction_id' => 1, + 'description' => 'срок обучения 4.5 года', + ], + [ + 'position' => 1, + 'period' => 5, + 'education_form_id' => 2, + 'direction_id' => 1, + 'description' => 'срок обучения 5 года', + ], + ]); + } +} diff --git a/resources/views/admin/catalog/direction/period/create.blade.php b/resources/views/admin/catalog/direction/period/create.blade.php new file mode 100644 index 0000000..1558286 --- /dev/null +++ b/resources/views/admin/catalog/direction/period/create.blade.php @@ -0,0 +1,79 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Создать срок обучения

+ {{ Form::open(['url' => route('periods.store'), 'method' => 'POST', 'class' => '']) }} +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('period', 'Срок обучения') }} +
+
+ {{ Form::text('period', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('period') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки') }} +
+
+ {{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('direction_id') }} + @endif +
+ +
+ {{ Form::label('education_form_id', 'Форма обучения') }} +
+
+ {{ Form::select('education_form_id', $educationForms, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('education_form_id') }} + @endif +
+ + +
+ {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/period/edit.blade.php b/resources/views/admin/catalog/direction/period/edit.blade.php new file mode 100644 index 0000000..a987f4f --- /dev/null +++ b/resources/views/admin/catalog/direction/period/edit.blade.php @@ -0,0 +1,79 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+
+

Изменить Стоимость

+ {{ Form::open(['url' => route('periods.update', $period), 'method' => 'PATCH', 'class' => '']) }} +
+ +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::text('position', $period->position, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', $period->description, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+ +
+ {{ Form::label('period', 'Срок обучения') }} +
+
+ {{ Form::text('period', $period->period, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('period') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки') }} +
+
+ {{ Form::select('direction_id', $directions, $period->direction->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('direction_id') }} + @endif +
+ +
+ {{ Form::label('education_form_id', 'Форма обучения') }} +
+
+ {{ Form::select('education_form_id', $educationForms, $period->educationForm->id, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('education_form_id') }} + @endif +
+ + +
+ {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::close() }} +
+
+ @endauth +@endsection diff --git a/resources/views/admin/catalog/direction/period/index.blade.php b/resources/views/admin/catalog/direction/period/index.blade.php new file mode 100644 index 0000000..604ea08 --- /dev/null +++ b/resources/views/admin/catalog/direction/period/index.blade.php @@ -0,0 +1,45 @@ +@extends('layouts.admin_layout') +@section('content') +
+

Срок обучения

+
+ Создать срок обучения +
+
+ + + + + + + + + + + + + + @foreach($periods as $period) + + + + + + + + + @endforeach + +
позицияописаниеФорма обучениянаправлениеСрок обучениядействия
{{ $period->position }}{{ Str::words($period->description, 10, '...') }}{{ $period->educationForm->name }}{{ $period->direction->name }}{{ $period->period }} + посмотреть + редактировать + удалить +
+
+
+
+@endsection diff --git a/resources/views/admin/catalog/direction/period/show.blade.php b/resources/views/admin/catalog/direction/period/show.blade.php new file mode 100644 index 0000000..d9586c4 --- /dev/null +++ b/resources/views/admin/catalog/direction/period/show.blade.php @@ -0,0 +1,17 @@ +@extends('layouts.admin_layout') +@section('content') + @auth() +
+

позиция

+

{{ $period->position }}

+

описание

+

{{ $period->description }}

+

Форма обучения

+

{{ $period->educationForm->name }}

+

Направление

+

{{ $period->direction->name }}

+

Срок обучения

+

{{ $period->period }}

+
+ @endauth +@endsection diff --git a/resources/views/layouts/admin_layout.blade.php b/resources/views/layouts/admin_layout.blade.php index b06451c..c2c8492 100644 --- a/resources/views/layouts/admin_layout.blade.php +++ b/resources/views/layouts/admin_layout.blade.php @@ -65,6 +65,7 @@
  • Кол-во Мест
  • Типы Мест
  • Стоимость об.
  • +
  • Срок. обучения
  • Профили подготовки
  • diff --git a/routes/admin.php b/routes/admin.php index 6537b0c..88a4e73 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -8,6 +8,7 @@ use App\Http\Controllers\admin\Catalog\Direction\EducationFormController; use App\Http\Controllers\admin\Catalog\Direction\EducationLevelController; use App\Http\Controllers\admin\Catalog\Direction\EntranceExaminationController; use App\Http\Controllers\admin\Catalog\Direction\ExaminationTypeController; +use App\Http\Controllers\admin\Catalog\Direction\PeriodController; use App\Http\Controllers\admin\Catalog\Direction\PlaceController; use App\Http\Controllers\admin\Catalog\Direction\PlaceTypeController; use App\Http\Controllers\admin\Catalog\Direction\SubjectController; @@ -65,6 +66,7 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () { Route::resource('/places', PlaceController::class); Route::resource('/costs', CostController::class); + Route::resource('/periods', PeriodController::class); Route::resource('/direction_profiles', DirectionProfileController::class) ->scoped(['direction_profile' => 'slug']); diff --git a/tests/Feature/admin/catalog/direction/PeriodTest.php b/tests/Feature/admin/catalog/direction/PeriodTest.php new file mode 100644 index 0000000..39b5b92 --- /dev/null +++ b/tests/Feature/admin/catalog/direction/PeriodTest.php @@ -0,0 +1,116 @@ +create(); + Faculty::factory()->create(); + Department::factory()->create(); + EducationLevel::factory()->create(); + EducationForm::factory()->create(); + Direction::factory()->create(); + + $this->period = Period::factory()->create(); + + $this->data = Period::factory()->make()->only([ + 'position', + 'description', + 'period', + 'education_form_id', + 'direction_id', + ]); + + $this->user = User::factory()->create([ + 'name' => 'admin', + 'email' => 'test@example.com', + 'password' => 123456 + ]); + } + + public function testIndexPeriodsPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('periods.index')); + + $response->assertOk(); + } + + public function testCreatePeriodPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('periods.create')); + + $response->assertOk(); + } + + public function testStorePeriod(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->post(route('periods.store', $this->data)); + + $response->assertRedirect(route('periods.index')); + + $this->assertDatabaseHas('periods', $this->data); + } + + public function testShowPeriod(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('periods.show', $this->period)); + + $response->assertOk(); + } + + public function testEditPeriodPage(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->get(route('periods.edit', $this->period)); + + $response->assertOk(); + } + + public function testUpdatePeriod(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->patch(route('periods.update', $this->period), $this->data); + + $response->assertRedirect(route('periods.index')); + + $this->assertDatabaseHas('periods', $this->data); + } + + public function testDestroyPeriod(): void + { + $response = $this->actingAs($this->user) + ->withSession(['banned' => false]) + ->delete(route('periods.destroy', $this->period)); + + $response->assertRedirect(route('periods.index')); + + $this->assertDatabaseMissing('periods', $this->period->toArray()); + } +}