applicant-site/app/Http/Controllers/admin/Catalog/Direction/EntranceExaminationControll...

105 lines
3.7 KiB
PHP
Raw Normal View History

2024-02-19 10:51:20 +03:00
<?php
namespace App\Http\Controllers\admin\Catalog\Direction;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\Direction\StoreEntranceExaminationRequest;
use App\Http\Requests\admin\Catalog\Direction\UpdateEntranceExaminationRequest;
use App\Models\Direction;
use App\Models\EntranceExamination;
use App\Models\ExaminationType;
use App\Models\Subject;
use App\Models\SubjectType;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class EntranceExaminationController extends Controller
{
public function index(): View
{
$entranceExaminations = EntranceExamination::all();
return view('admin.catalog.direction.entrance_examination.index', compact('entranceExaminations'));
}
public function create(): View
{
$directions = Direction::pluck('name', 'id');
$examination_types = ExaminationType::pluck('name', 'id');
$subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id');
return view(
'admin.catalog.direction.entrance_examination.create',
compact(
'directions',
'examination_types',
'subjects',
'subjectTypes',
)
);
}
public function store(StoreEntranceExaminationRequest $request): RedirectResponse
{
$validated = $request->validated();
$entranceExamination = new EntranceExamination();
$entranceExamination->examination_type_id = $validated['examination_type_id'];
$entranceExamination->direction_id = $validated['direction_id'];
$entranceExamination->subject_id = $validated['subject_id'];
$entranceExamination->scores = $validated['scores'];
$entranceExamination->position = $validated['position'];
$entranceExamination->subject_type_id = $validated['subject_type_id'];
$entranceExamination->save();
return redirect()->route('entrance_examinations.index');
}
public function show(EntranceExamination $entranceExamination): View
{
return view(
'admin.catalog.direction.entrance_examination.show',
compact('entranceExamination')
);
}
public function edit(EntranceExamination $entranceExamination): View
{
$directions = Direction::pluck('name', 'id');
$examination_types = ExaminationType::pluck('name', 'id');
$subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id');
return view(
'admin.catalog.direction.entrance_examination.edit',
compact(
'entranceExamination',
'directions',
'examination_types',
'subjects',
'subjectTypes',
)
);
}
public function update(UpdateEntranceExaminationRequest $request, EntranceExamination $entranceExamination): RedirectResponse
{
$validated = $request->validated();
$entranceExamination->examination_type_id = $validated['examination_type_id'];
$entranceExamination->direction_id = $validated['direction_id'];
$entranceExamination->subject_id = $validated['subject_id'];
$entranceExamination->scores = $validated['scores'];
$entranceExamination->position = $validated['position'];
$entranceExamination->subject_type_id = $validated['subject_type_id'];
$entranceExamination->save();
return redirect()->route('entrance_examinations.index');
}
public function destroy(EntranceExamination $entranceExamination): RedirectResponse
{
$entranceExamination->delete();
return redirect()->route('entrance_examinations.index');
}
}