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

135 lines
4.9 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;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
2024-02-19 10:51:20 +03:00
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
{
2024-02-28 15:05:54 +03:00
$directions = Direction::pluck('full_name', 'id');
2024-02-19 10:51:20 +03:00
$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]
);
2024-02-19 10:51:20 +03:00
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
{
2024-02-28 15:05:54 +03:00
$directions = Direction::pluck('full_name', 'id');
2024-02-19 10:51:20 +03:00
$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();
2024-02-19 10:51:20 +03:00
$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
]
);
2024-02-19 10:51:20 +03:00
$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(),
]
);
2024-02-19 10:51:20 +03:00
$entranceExamination->delete();
return redirect()->route('entrance_examinations.index');
}
}