Skip to content

Commit

Permalink
Added clone to consumables
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>
  • Loading branch information
snipe committed Jul 20, 2024
1 parent 2bfee0c commit 254e2f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Http/Controllers/Consumables/ConsumablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,14 @@ public function show($consumableId = null)
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);
}
}
1 change: 1 addition & 0 deletions app/Http/Transformers/ConsumablesTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function transformConsumable(Consumable $consumable)
'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;

Expand Down
4 changes: 4 additions & 0 deletions routes/web/consumables.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
[Consumables\ConsumablesFilesController::class, 'show']
)->name('show.consumablefile');

Route::get('{consumable}/clone',
[Consumables\ConsumablesController::class, 'clone']
)->name('consumables.clone.create');


});

Expand Down

0 comments on commit 254e2f1

Please sign in to comment.