add middleware auth, optimize abort_if

This commit is contained in:
aslan 2024-01-25 10:51:29 +03:00
parent 52d2073dee
commit 956681c0b3
1 changed files with 8 additions and 3 deletions

View File

@ -12,6 +12,10 @@ use Illuminate\Support\Facades\Auth;
class ReceptionScreenController extends Controller class ReceptionScreenController extends Controller
{ {
public function __construct()
{
$this->middleware('auth');
}
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{ {
$receptionScreens = ReceptionScreen::all()->sortBy('position'); $receptionScreens = ReceptionScreen::all()->sortBy('position');
@ -20,9 +24,8 @@ class ReceptionScreenController extends Controller
public function create(): View public function create(): View
{ {
if (Auth::guest()) { abort_if(Auth::guest(), 403);
abort(403);
}
$receptionScreens = ReceptionScreen::all()->sortBy('position'); $receptionScreens = ReceptionScreen::all()->sortBy('position');
return view('admin-reception-screen.create', compact('receptionScreens')); return view('admin-reception-screen.create', compact('receptionScreens'));
} }
@ -39,6 +42,8 @@ class ReceptionScreenController extends Controller
} }
public function edit($id) public function edit($id)
{ {
abort_if(Auth::guest(), 403);
$receptionScreen = new ReceptionScreen(); $receptionScreen = new ReceptionScreen();
$currentReceptionScreen = $receptionScreen->find($id); $currentReceptionScreen = $receptionScreen->find($id);
$receptionScreens = $receptionScreen->all()->sortBy('position'); $receptionScreens = $receptionScreen->all()->sortBy('position');