Handle deletions on the observer

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-11 17:26:43 +01:00
parent c2fe3b5459
commit 1527679f4b
3 changed files with 26 additions and 3 deletions

View file

@ -70,15 +70,19 @@ class ConsumableObserver
{ {
$consumable->users()->detach(); $consumable->users()->detach();
$uploads = $consumable->uploads;
foreach ($consumable->uploads() as $file) { foreach ($uploads as $file) {
try { try {
Storage::disk('public')->delete('consumables/'.$file); Storage::delete('private_uploads/consumables/'.$file->filename);
$file->delete();
} catch (\Exception $e) { } catch (\Exception $e) {
Log::info($e); Log::info($e);
} }
} }
try { try {
Storage::disk('public')->delete('consumables/'.$consumable->image); Storage::disk('public')->delete('consumables/'.$consumable->image);
} catch (\Exception $e) { } catch (\Exception $e) {

View file

@ -37,6 +37,25 @@
</div> </div>
@endif @endif
<!-- total -->
<div class="form-group">
<label class="col-sm-3 control-label">{{ trans('admin/components/general.total') }}</label>
<div class="col-md-6">
<p class="form-control-static">{{ $consumable->qty }}</p>
</div>
</div>
<!-- remaining -->
<div class="form-group">
<label class="col-sm-3 control-label">{{ trans('admin/components/general.remaining') }}</label>
<div class="col-md-6">
<p class="form-control-static">{{ $consumable->numRemaining() }}</p>
</div>
</div>
<!-- User --> <!-- User -->
@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to', 'required'=> 'true']) @include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to', 'required'=> 'true'])

View file

@ -351,7 +351,7 @@
@can('delete', $consumable) @can('delete', $consumable)
<div class="col-md-12" style="padding-top: 30px; padding-bottom: 30px;"> <div class="col-md-12" style="padding-top: 30px; padding-bottom: 30px;">
@if ($consumable->deleted_at=='') @if ($consumable->deleted_at=='')
<button class="btn btn-sm btn-block btn-danger delete-asset" data-toggle="modal" data-title="{{ trans('general.delete') }}" data-content="{{ trans('general.sure_to_delete_var', ['item' => $consumable->id]) }}" data-target="#dataConfirmModal">{{ trans('general.delete') }} <button class="btn btn-sm btn-block btn-danger delete-asset" data-toggle="modal" data-title="{{ trans('general.delete') }}" data-content="{{ trans('general.sure_to_delete_var', ['item' => $consumable->name]) }}" data-target="#dataConfirmModal">{{ trans('general.delete') }}
</button> </button>
<span class="sr-only">{{ trans('general.delete') }}</span> <span class="sr-only">{{ trans('general.delete') }}</span>
@endif @endif