From a7b2fd58d50cd0b06e3eaf24c8647cb712984e03 Mon Sep 17 00:00:00 2001 From: aslan Date: Thu, 25 Jan 2024 10:22:23 +0300 Subject: [PATCH] add methods edit, delete, update for reception screen --- .../Controllers/ReceptionScreenController.php | 52 +++++++++++-------- .../admin-reception-screen/create.blade.php | 6 +-- .../admin-reception-screen/edit.blade.php | 15 +++--- .../admin-reception-screen/index.blade.php | 14 ++--- 4 files changed, 47 insertions(+), 40 deletions(-) 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) - {{ $onlineDocument->position }} - {{ $onlineDocument->name }} + {{ $receptionScreen->position }} + {{ $receptionScreen->name }} @endforeach diff --git a/resources/views/admin-reception-screen/edit.blade.php b/resources/views/admin-reception-screen/edit.blade.php index 7bff02e..82c7eff 100644 --- a/resources/views/admin-reception-screen/edit.blade.php +++ b/resources/views/admin-reception-screen/edit.blade.php @@ -5,13 +5,14 @@

Изменить пункт Экрана приема

- {{ Form::open(['url' => route('admin-reception-screen.update', $currentOnlineDocument), 'method' => 'PATCH', 'class' => '']) }} + + {{ Form::open(['url' => route('admin-reception-screen.update', $currentReceptionScreen), 'method' => 'PATCH', 'class' => '']) }}
{{ Form::label('position', 'Позиция') }}
- {{ Form::text('position', $currentOnlineDocument->position, ['class' => 'form-control']) }} + {{ Form::text('position', $currentReceptionScreen->position, ['class' => 'form-control']) }}
@if ($errors->any()) @@ -23,7 +24,7 @@ {{ Form::label('name', 'Название') }}
- {{ Form::text('name', '', ['class' => 'form-control']) }} + {{ Form::text('name', $currentReceptionScreen->name, ['class' => 'form-control']) }}
@if ($errors->any()) @@ -32,7 +33,7 @@
- {{ Form::submit('создать', ['class' => 'btn btn-primary']) }} + {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
{{ Form::close() }} @@ -46,10 +47,10 @@ - @foreach($onlineDocuments as $onlineDocument) + @foreach($receptionScreens as $receptionScreen) - {{ $onlineDocument->position }} - {{ $onlineDocument->name }} + {{ $receptionScreen->position }} + {{ $receptionScreen->name }} @endforeach diff --git a/resources/views/admin-reception-screen/index.blade.php b/resources/views/admin-reception-screen/index.blade.php index 540119b..378847e 100644 --- a/resources/views/admin-reception-screen/index.blade.php +++ b/resources/views/admin-reception-screen/index.blade.php @@ -15,17 +15,17 @@ - @foreach($onlineDocuments as $onlineDocument) + @foreach($receptionScreens as $receptionScreen) - {{ $onlineDocument->position }} - {{ $onlineDocument->name }} - редактировать + {{ $receptionScreen->position }} + {{ $receptionScreen->name }} + редактировать + href="{{ route('admin-reception-screen.destroy', $receptionScreen) }}" class="btn btn-danger"> удалить - @if(count($onlineDocument->files) !== 0) + @if(count($receptionScreen->files) !== 0) @@ -39,7 +39,7 @@ - @foreach($onlineDocument->files->sortBy('position') as $file) + @foreach($receptionScreen->files->sortBy('position') as $file) {{ $file->position }} {{ $file->name }}