diff --git a/app/Http/Controllers/admin/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php index 969add8..be3584d 100644 --- a/app/Http/Controllers/admin/Catalog/DirectionController.php +++ b/app/Http/Controllers/admin/Catalog/DirectionController.php @@ -9,7 +9,11 @@ use App\Models\Department; use App\Models\Direction; use App\Models\EducationForm; use App\Models\EducationLevel; +use App\Models\EntranceExamination; +use App\Models\ExaminationType; use App\Models\Faculty; +use App\Models\Subject; +use App\Models\SubjectType; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Foundation\Application; @@ -28,15 +32,19 @@ class DirectionController extends Controller $levels = EducationLevel::pluck('name', 'id'); $forms = EducationForm::pluck('name', 'id'); $departments = Department::pluck('name', 'id'); - return view('admin.catalog.direction.create', compact('departments', 'levels', 'forms')); + $examination_types = ExaminationType::pluck('name', 'id'); + $subjects = Subject::pluck('name', 'id'); + $subjectTypes = SubjectType::pluck('name', 'id'); + return view('admin.catalog.direction.create', + compact('departments', 'levels', 'forms', 'examination_types', 'subjectTypes', 'subjects')); } public function store(StoreDirectionRequest $request): RedirectResponse { $validated = $request->validated(); - $direction = new Direction(); $direction->name = $validated['name']; + $direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->description = $validated['description']; $direction->position = $validated['position']; $direction->slug = $validated['slug']; @@ -46,6 +54,19 @@ class DirectionController extends Controller $direction->department_id = $validated['department_id']; $direction->save(); + if(array_key_exists('entrance-examination', $validated)) { + foreach ($validated['entrance-examination'] as $data) { + $entranceExamination = new EntranceExamination(); + $entranceExamination->examination_type_id = $data['examination_type_id']; + $entranceExamination->direction_id = $direction->id; + $entranceExamination->subject_id = $data['subject_id']; + $entranceExamination->scores = $data['scores']; + $entranceExamination->position = $data['position']; + $entranceExamination->subject_type_id = $data['subject_type_id']; + $entranceExamination->save(); + } + } + return redirect()->route('directions.index'); } @@ -55,17 +76,38 @@ class DirectionController extends Controller $faculty = Faculty::find($department->faculty->id); $educationalInstitution = $faculty->educationalInstitution; - $ege = $direction->entranceExaminations->where('examination_type_id', '=', '1')->pluck('scores', 'subject_id'); - $spo = $direction->entranceExaminations->where('examination_type_id', '=', '2')->pluck('scores', 'subject_id'); + $ege = $direction + ->entranceExaminations + ->where('examination_type_id', '=', '1') + ->sortBy('position') + ->pluck('scores', 'subject_id'); + + $spo = $direction + ->entranceExaminations->where('examination_type_id', '=', '2') + ->sortBy('position') + ->pluck('scores', 'subject_id'); + $magistracy = $direction ->entranceExaminations ->where('examination_type_id', '=', '3') ->pluck('scores', 'subject_id'); - $budget = $direction->places->where('place_type_id', '=', '1')->pluck('amount', 'education_form_id'); - $paid = $direction->places->where('place_type_id', '=', '2')->pluck('amount', 'education_form_id'); + $budget = $direction + ->places + ->where('place_type_id', '=', '1') + ->sortBy('position') + ->pluck('amount', 'education_form_id'); - $costs = $direction->costs->pluck('cost', 'education_form_id'); + $paid = $direction + ->places + ->where('place_type_id', '=', '2') + ->sortBy('position') + ->pluck('amount', 'education_form_id'); + + $costs = $direction + ->costs + ->sortBy('position') + ->pluck('cost', 'education_form_id'); return view( 'admin.catalog.direction.show', @@ -96,8 +138,8 @@ class DirectionController extends Controller { $validated = $request->validated(); - $direction = new Direction(); $direction->name = $validated['name']; + $direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->description = $validated['description']; $direction->position = $validated['position']; $direction->slug = $validated['slug']; diff --git a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php index b78c4e5..27d05a4 100644 --- a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php @@ -15,13 +15,18 @@ class StoreDirectionRequest extends FormRequest { return [ 'position' => 'required|int|numeric|max:255', - 'name' => 'required|string|max:255|unique:directions,name', + 'name' => 'required|string|max:255', 'description' => 'string', 'slug' => 'required|string|max:255|unique:directions,slug', - 'code' => 'required|string|max:255', + 'code' => 'required|string|max:255|unique:directions,code', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', - 'department_id' => 'required|numeric|int|max:1000' + 'department_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.examination_type_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.subject_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.subject_type_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.scores' => 'required|numeric|int|max:1000', + 'entrance-examination.*.position' => 'required|numeric|int|max:1000', ]; } } diff --git a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php index d9e862b..ad6d87f 100644 --- a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php @@ -24,14 +24,14 @@ class UpdateDirectionRequest extends FormRequest 'max:255', "unique:directions,slug,{$this->direction->id}", ], - 'code' => 'required|string|max:255', + 'name' => 'required|string|max:255', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', - 'name' => [ + 'code' => [ 'required', 'string', 'max:255', - "unique:directions,name,{$this->direction->id}", + "unique:directions,code,{$this->direction->id}", ], ]; } diff --git a/app/Models/Direction.php b/app/Models/Direction.php index 082638e..7ece0d1 100644 --- a/app/Models/Direction.php +++ b/app/Models/Direction.php @@ -14,6 +14,7 @@ class Direction extends Model protected $fillable = [ 'id', 'name', + 'full_name', 'description', 'position', 'slug', diff --git a/database/factories/DirectionFactory.php b/database/factories/DirectionFactory.php index a66584a..57ad9c5 100644 --- a/database/factories/DirectionFactory.php +++ b/database/factories/DirectionFactory.php @@ -8,11 +8,14 @@ class DirectionFactory extends Factory { public function definition(): array { + $name = fake()->name(); + $code = fake()->text(10); return [ - 'name' => fake()->name(), + 'name' => $name, + 'full_name' => "{$code} {$name}", 'description' => fake()->text(), 'slug' => fake()->slug(), - 'code' => fake()->text(50), + 'code' => $code, 'position' => fake()->randomDigit(), 'department_id' => 1, 'education_level_id' => 1, 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 63d2318..6e2cc3c 100644 --- a/database/migrations/2024_02_09_114155_create_directions_table.php +++ b/database/migrations/2024_02_09_114155_create_directions_table.php @@ -11,6 +11,7 @@ return new class extends Migration Schema::create('directions', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('full_name'); $table->text('description')->nullable(); $table->string('code'); $table->integer('position'); diff --git a/database/seeders/DirectionSeeder.php b/database/seeders/DirectionSeeder.php index 7938a5a..b2bf20e 100644 --- a/database/seeders/DirectionSeeder.php +++ b/database/seeders/DirectionSeeder.php @@ -13,6 +13,7 @@ class DirectionSeeder extends Seeder DB::table('directions')->insert([ [ 'name' => 'Юриспруденция', + 'full_name' => '40.03.01 Юриспруденция', 'description' => 'Юриспруденция', 'slug' => 'jurisprudence', 'code' => '40.03.01', @@ -23,6 +24,7 @@ class DirectionSeeder extends Seeder ], [ 'name' => 'фармация', + 'full_name' => '33.05.01 фармация', 'description' => 'фармация', 'slug' => 'pharmacy', 'code' => '33.05.01', @@ -33,6 +35,7 @@ class DirectionSeeder extends Seeder ], [ 'name' => 'строительство', + 'full_name' => '08.04.01 строительство', 'description' => 'строительство', 'slug' => 'construction', 'code' => '08.04.01', diff --git a/resources/views/admin/catalog/direction/create.blade.php b/resources/views/admin/catalog/direction/create.blade.php index e14aa6c..cebd615 100644 --- a/resources/views/admin/catalog/direction/create.blade.php +++ b/resources/views/admin/catalog/direction/create.blade.php @@ -1,46 +1,74 @@ @extends('layouts.admin_layout') @section('content') @auth() +