From 254e2f120b428bcb8e6823df891fa00ac9052355 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 20 Jul 2024 16:40:32 +0100 Subject: [PATCH] Added clone to consumables Signed-off-by: snipe --- .../Controllers/Consumables/ConsumablesController.php | 10 ++++++++++ app/Http/Transformers/ConsumablesTransformer.php | 1 + routes/web/consumables.php | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/app/Http/Controllers/Consumables/ConsumablesController.php b/app/Http/Controllers/Consumables/ConsumablesController.php index 9dd17fe6bc..f746b9f904 100644 --- a/app/Http/Controllers/Consumables/ConsumablesController.php +++ b/app/Http/Controllers/Consumables/ConsumablesController.php @@ -209,4 +209,14 @@ class ConsumablesController extends Controller return redirect()->route('consumables.index') ->with('error', trans('admin/consumables/message.does_not_exist')); } + + public function clone(Consumable $consumable) : View + { + $this->authorize('create', $consumable); + $consumable_to_close = $consumable; + $consumable = clone $consumable_to_close; + $consumable->id = null; + + return view('consumables/edit')->with('item', $consumable); + } } diff --git a/app/Http/Transformers/ConsumablesTransformer.php b/app/Http/Transformers/ConsumablesTransformer.php index f23ebc0382..d0ae57eef0 100644 --- a/app/Http/Transformers/ConsumablesTransformer.php +++ b/app/Http/Transformers/ConsumablesTransformer.php @@ -55,6 +55,7 @@ class ConsumablesTransformer 'checkin' => Gate::allows('checkin', Consumable::class), 'update' => Gate::allows('update', Consumable::class), 'delete' => Gate::allows('delete', Consumable::class), + 'clone' => (Gate::allows('create', Consumable::class) && ($consumable->deleted_at == '')), ]; $array += $permissions_array; diff --git a/routes/web/consumables.php b/routes/web/consumables.php index 4e2472d30c..8e6c94d863 100644 --- a/routes/web/consumables.php +++ b/routes/web/consumables.php @@ -31,6 +31,10 @@ Route::group(['prefix' => 'consumables', 'middleware' => ['auth']], function () [Consumables\ConsumablesFilesController::class, 'show'] )->name('show.consumablefile'); + Route::get('{consumable}/clone', + [Consumables\ConsumablesController::class, 'clone'] + )->name('consumables.clone.create'); + });