Skip to content

A free open source IT asset/license management system

add accessor for category name on checkout acceptance model

Godfrey Mb7f6137a63ad
diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php
index b36ab2513f..18f8e13439 100644
--- a/app/Models/CheckoutAcceptance.php
+++ b/app/Models/CheckoutAcceptance.php
@@ -48,6 +48,24 @@ class CheckoutAcceptance extends Model
default => class_basename($type),
};
}
+ public function getCheckoutableCategoryNameAttribute(): ?string
+ {
+ $item = $this->checkoutable;
+
+ if (! $item) {
+ return null;
+ }
+
+ return match (true) {
+ $item instanceof Asset => $item->model?->category?->name,
+ $item instanceof LicenseSeat => $item->license?->category?->name,
+ $item instanceof Accessory,
+ $item instanceof Component,
+ $item instanceof Consumable => $item->category?->name,
+
+ default => null,
+ };
+ }
/**
* The resource that was is out
*
diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php
index 2311b40d8e..d728e08345 100755
--- a/resources/views/account/accept/index.blade.php
+++ b/resources/views/account/accept/index.blade.php
@@ -43,7 +43,7 @@
@if ($acceptance->checkoutable)
<td>{{ ($acceptance->checkoutable) ? $acceptance->checkoutable->present()->name : '' }}</td>
<td>{{ $acceptance->checkoutable_item_type }}</td>
- <td>{{ $acceptance->checkoutable->model?->category?->name }}</td>
+ <td>{{ $acceptance->checkoutableCategoryName ?? '' }}</td>
<td>{{ $acceptance->qty ?? '1' }}</td>
<td>{{ ($acceptance->checkoutable) ? $acceptance->checkoutable->serial : '' }}</td>
<td><a href="{{ route('account.accept.item', $acceptance) }}" class="btn btn-theme btn-sm">{{ trans('general.accept_decline') }}</a></td>