forked from aslan/applicant-site
83 lines
2.6 KiB
PHP
83 lines
2.6 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 __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
return view('admin-reception-screen.index', compact('receptionScreens'));
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
return view('admin-reception-screen.create', compact('receptionScreens'));
|
|
}
|
|
|
|
public function store(StoreReceptionScreenRequest $request)
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$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)
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$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)
|
|
{
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
$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');
|
|
}
|
|
}
|