diff --git a/app/Http/Controllers/ReceptionScreenController.php b/app/Http/Controllers/ReceptionScreenController.php index 31708a3..cb29ed1 100644 --- a/app/Http/Controllers/ReceptionScreenController.php +++ b/app/Http/Controllers/ReceptionScreenController.php @@ -14,8 +14,8 @@ class ReceptionScreenController extends Controller { public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application { - $onlineDocuments = ReceptionScreen::all()->sortBy('position'); - return view('admin-reception-screen.index', compact('onlineDocuments')); + $receptionScreens = ReceptionScreen::all()->sortBy('position'); + return view('admin-reception-screen.index', compact('receptionScreens')); } public function create(): View @@ -29,10 +29,6 @@ class ReceptionScreenController extends Controller public function store(StoreReceptionScreenRequest $request) { - if (Auth::guest()) { - abort(403, 'Вы не авторизованы!'); - } - $validated = $request->validated(); $receptionScreen = new ReceptionScreen(); $receptionScreen->name = $validated['name']; @@ -41,25 +37,35 @@ class ReceptionScreenController extends Controller return redirect()->route('admin-reception-screen.index'); } - public function edit(ReceptionScreen $currentOnlineDocument) + public function edit($id) { - if (Auth::guest()) { - abort(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) + { + $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(); } - $onlineDocuments = ReceptionScreen::all()->sortBy('position'); - return view('admin-reception-screen.edit', compact('currentOnlineDocument', 'onlineDocuments')); - } + $currentReceptionScreen->delete(); - public function update(UpdateReceptionScreenRequest $request, ReceptionScreen $doceumentsOnline) - { - // - } - - /** - * Remove the specified resource from storage. - */ - public function destroy(ReceptionScreen $doceumentsOnline) - { - // + return redirect()->route('admin-reception-screen.index'); } } diff --git a/resources/views/admin-reception-screen/create.blade.php b/resources/views/admin-reception-screen/create.blade.php index bd76efc..5d14036 100644 --- a/resources/views/admin-reception-screen/create.blade.php +++ b/resources/views/admin-reception-screen/create.blade.php @@ -46,10 +46,10 @@
- @foreach($onlineDocuments as $onlineDocument) + @foreach($receptionScreens as $receptionScreen)