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

139 lines
5.0 KiB
PHP

<?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;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
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('full_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();
Log::channel('app')
->info(
'CREATE вступ. испытания {entranceExamination} - user {user}',
[
'user' => Auth::user()->name,
'entranceExamination' => $entranceExamination->name,
'data' => $validated
]
);
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('full_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();
$oldData = $entranceExamination->toArray();
$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'];
Log::channel('app')
->warning(
'UPDATE вступ. испытания {entranceExamination} - user {user}',
[
'user' => Auth::user()->name,
'entranceExamination' => $entranceExamination->name,
'oldData' => $oldData,
'newData' => $validated
]
);
$entranceExamination->save();
return redirect()->route('entrance_examinations.index');
}
public function destroy(EntranceExamination $entranceExamination): RedirectResponse
{
Log::channel('app')
->critical(
'DELETE вступ. испытания {entranceExamination} - user {user}',
[
'user' => Auth::user()->name,
'entranceExamination' => $entranceExamination->name,
'data' => $entranceExamination->toArray(),
]
);
$entranceExamination->delete();
return redirect()->route('entrance_examinations.index');
}
}