Skip to content

A free open source IT asset/license management system

Fixed error if item requested or request was deleted (#6786)

snipe6d98bd684641
diff --git a/app/Http/Controllers/Api/ProfileController.php b/app/Http/Controllers/Api/ProfileController.php
index 378945f855..0798381884 100644
--- a/app/Http/Controllers/Api/ProfileController.php
+++ b/app/Http/Controllers/Api/ProfileController.php
@@ -27,15 +27,20 @@ class ProfileController extends Controller
foreach ($checkoutRequests as $checkoutRequest) {
- $results['rows'][] = [
- 'image' => $checkoutRequest->itemRequested()->present()->getImageUrl(),
- 'name' => $checkoutRequest->itemRequested()->present()->name(),
- 'type' => $checkoutRequest->itemType(),
- 'qty' => $checkoutRequest->quantity,
- 'location' => ($checkoutRequest->location()) ? $checkoutRequest->location()->name : null,
- 'expected_checkin' => Helper::getFormattedDateObject($checkoutRequest->itemRequested()->expected_checkin, 'datetime'),
- 'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'),
- ];
+
+ // Make sure the asset and request still exist
+ if ($checkoutRequest && $checkoutRequest->itemRequested()) {
+ $results['rows'][] = [
+ 'image' => $checkoutRequest->itemRequested()->present()->getImageUrl(),
+ 'name' => $checkoutRequest->itemRequested()->present()->name(),
+ 'type' => $checkoutRequest->itemType(),
+ 'qty' => $checkoutRequest->quantity,
+ 'location' => ($checkoutRequest->location()) ? $checkoutRequest->location()->name : null,
+ 'expected_checkin' => Helper::getFormattedDateObject($checkoutRequest->itemRequested()->expected_checkin, 'datetime'),
+ 'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'),
+ ];
+ }
+
}
return $results;
}