Skip to content

A free open source IT asset/license management system

update accessor to laravel 11.x standards

Godfrey Ma8c77d6e268f
diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php
index 18f8e13439..b9895d92bc 100644
--- a/app/Models/CheckoutAcceptance.php
+++ b/app/Models/CheckoutAcceptance.php
@@ -48,23 +48,29 @@ class CheckoutAcceptance extends Model
default => class_basename($type),
};
}
- public function getCheckoutableCategoryNameAttribute(): ?string
+ /**
+ * Accessor for the checkoutable item's category name.
+ *
+ * @return Attribute
+ */
+ protected function checkoutableCategoryName(): Attribute
{
- $item = $this->checkoutable;
+ return Attribute::make(
+ get: function () {
+ $item = $this->checkoutable;
- if (! $item) {
- return null;
- }
+ if ($item instanceof Asset) {
- 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,
+ return $item->model?->category?->name;
+ }
+ if ($item instanceof LicenseSeat) {
- default => null,
- };
+ return $item->license?->category?->name;
+ }
+
+ return $item->category?->name;
+ },
+ );
}
/**
* 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 d728e08345..a8958ae5f2 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->checkoutableCategoryName ?? '' }}</td>
+ <td>{{ $acceptance->checkoutable_category_name ?? '' }}</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>