Roman_applicant-site/app/Http/Controllers/admin/AdmissionController.php

73 lines
2.0 KiB
PHP

<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\StoreAdmissionRequest;
use App\Http\Requests\admin\UpdateAdmissionRequest;
use App\Models\Admission;
class AdmissionController extends Controller
{
public function index()
{
$admissions = Admission::all()->sortBy('position');
return view('admin.admission.index', compact('admissions'));
}
public function create()
{
$admissions = Admission::all()->sortBy('position');
return view('admin.admission.create', compact('admissions'));
}
public function store(StoreAdmissionRequest $request)
{
$validated = $request->validated();
$admission = new Admission();
$admission->name = $validated['name'];
$admission->description = $validated['description'];
$admission->slug = $validated['slug'];
$admission->position = $validated['position'];
$admission->save();
return redirect()->route('admissions.index');
}
public function show(Admission $admission)
{
return view('admin.admission.show', compact('admission'));
}
public function edit(Admission $admission)
{
return view('admin.admission.edit', compact('admission'));
}
public function update(UpdateAdmissionRequest $request, Admission $admission)
{
$validated = $request->validated();
$admission->name = $validated['name'];
$admission->description = $validated['description'];
$admission->slug = $validated['slug'];
$admission->position = $validated['position'];
$admission->save();
return redirect()->route('admissions.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Admission $admission)
{
if ($admission->documents()->exists()) {
return back();
}
$admission->delete();
return redirect()->route('admissions.index');
}
}