2024-01-23 11:20:15 +03:00
|
|
|
<?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
|
|
|
|
{
|
2024-01-25 10:51:29 +03:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
2024-01-23 11:20:15 +03:00
|
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
2024-01-25 10:22:23 +03:00
|
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
|
|
return view('admin-reception-screen.index', compact('receptionScreens'));
|
2024-01-23 11:20:15 +03:00
|
|
|
}
|
|
|
|
|
2024-01-24 15:41:20 +03:00
|
|
|
public function create(): View
|
2024-01-23 11:20:15 +03:00
|
|
|
{
|
2024-01-25 10:51:29 +03:00
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
2024-01-25 08:59:34 +03:00
|
|
|
$receptionScreens = ReceptionScreen::all()->sortBy('position');
|
|
|
|
return view('admin-reception-screen.create', compact('receptionScreens'));
|
2024-01-23 11:20:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(StoreReceptionScreenRequest $request)
|
|
|
|
{
|
2024-01-25 08:59:34 +03:00
|
|
|
$validated = $request->validated();
|
|
|
|
$receptionScreen = new ReceptionScreen();
|
|
|
|
$receptionScreen->name = $validated['name'];
|
|
|
|
$receptionScreen->position = $validated['position'];
|
|
|
|
$receptionScreen->save();
|
2024-01-23 11:20:15 +03:00
|
|
|
|
2024-01-25 08:59:34 +03:00
|
|
|
return redirect()->route('admin-reception-screen.index');
|
|
|
|
}
|
2024-01-25 10:22:23 +03:00
|
|
|
public function edit($id)
|
2024-01-23 11:20:15 +03:00
|
|
|
{
|
2024-01-25 10:51:29 +03:00
|
|
|
abort_if(Auth::guest(), 403);
|
|
|
|
|
2024-01-25 10:22:23 +03:00
|
|
|
$receptionScreen = new ReceptionScreen();
|
|
|
|
$currentReceptionScreen = $receptionScreen->find($id);
|
|
|
|
$receptionScreens = $receptionScreen->all()->sortBy('position');
|
|
|
|
return view('admin-reception-screen.edit', compact('currentReceptionScreen', 'receptionScreens'));
|
2024-01-23 11:20:15 +03:00
|
|
|
}
|
|
|
|
|
2024-01-25 10:22:23 +03:00
|
|
|
public function update(UpdateReceptionScreenRequest $request, $id)
|
2024-01-23 11:20:15 +03:00
|
|
|
{
|
2024-01-25 10:22:23 +03:00
|
|
|
$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');
|
2024-01-23 11:20:15 +03:00
|
|
|
}
|
|
|
|
|
2024-01-25 10:22:23 +03:00
|
|
|
public function destroy($id)
|
2024-01-23 11:20:15 +03:00
|
|
|
{
|
2024-01-25 10:22:23 +03:00
|
|
|
$receptionScreen = new ReceptionScreen();
|
|
|
|
$currentReceptionScreen = $receptionScreen->find($id);
|
|
|
|
if ($currentReceptionScreen->files()->exists()) {
|
|
|
|
return back();
|
|
|
|
}
|
|
|
|
$currentReceptionScreen->delete();
|
|
|
|
|
|
|
|
return redirect()->route('admin-reception-screen.index');
|
2024-01-23 11:20:15 +03:00
|
|
|
}
|
|
|
|
}
|