forked from aslan/applicant-site
72 lines
2.4 KiB
PHP
72 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\StoreReceptionScreenRequest;
|
|
use App\Http\Requests\UpdateReceptionScreenRequest;
|
|
use App\Models\ReceptionScreen;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class ReceptionScreenController extends Controller
|
|
{
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
return view('admin-reception-screen.index', compact('receptionScreens'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
if (Auth::guest()) {
|
|
abort(403);
|
|
}
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
return view('admin-reception-screen.create', compact('receptionScreens'));
|
|
}
|
|
|
|
public function store(StoreReceptionScreenRequest $request)
|
|
{
|
|
$validated = $request->validated();
|
|
$receptionScreen = new ReceptionScreen();
|
|
$receptionScreen->name = $validated['name'];
|
|
$receptionScreen->position = $validated['position'];
|
|
$receptionScreen->save();
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
}
|
|
public function edit($id)
|
|
{
|
|
$receptionScreen = new ReceptionScreen();
|
|
$currentReceptionScreen = $receptionScreen->find($id);
|
|
$receptionScreens = $receptionScreen->all()->sortBy('position');
|
|
return view('admin-reception-screen.edit', compact('currentReceptionScreen', 'receptionScreens'));
|
|
}
|
|
|
|
public function update(UpdateReceptionScreenRequest $request, $id)
|
|
{
|
|
$validated = $request->validated();
|
|
$receptionScreen = new ReceptionScreen();
|
|
$currentReceptionScreen = $receptionScreen->find($id);
|
|
$currentReceptionScreen->name = $validated['name'];
|
|
$currentReceptionScreen->position = $validated['position'];
|
|
$currentReceptionScreen->save();
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$receptionScreen = new ReceptionScreen();
|
|
$currentReceptionScreen = $receptionScreen->find($id);
|
|
if ($currentReceptionScreen->files()->exists()) {
|
|
return back();
|
|
}
|
|
$currentReceptionScreen->delete();
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
}
|
|
}
|