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']; $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(); 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'); } public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { $department = $direction->department; $faculty = Faculty::find($department->faculty->id); $educationalInstitution = $faculty->educationalInstitution; $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') ->sortBy('position') ->pluck('amount', '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', compact( 'direction', 'educationalInstitution', 'faculty', 'department', 'ege', 'spo', 'magistracy', 'budget', 'paid', 'costs', ) ); } public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { $levels = EducationLevel::pluck('name', 'id'); $departments = Department::pluck('name', 'id'); $forms = EducationForm::pluck('name', 'id'); return view('admin.catalog.direction.edit', compact('direction', 'departments', 'levels', 'forms')); } public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse { $validated = $request->validated(); $direction->name = $validated['name']; $direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->description = $validated['description']; $direction->position = $validated['position']; $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(); return redirect()->route('directions.index'); } public function destroy(Direction $direction): RedirectResponse { if ($direction->entranceExaminations()->exists()) { return back(); } $direction->delete(); return redirect()->route('directions.index'); } }