From 6186c324b561060399ce9f9acc493f17cf8e6023 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2017 08:47:40 -0700 Subject: [PATCH] Misc assetLoc error checks --- app/Models/Asset.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 8a4d4eed8b..38bc1f3946 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -266,17 +266,23 @@ class Asset extends Depreciable throw new \Exception("Asset assignment Loop for Asset ID: ".$first_asset->id); } $assigned_to=Asset::find($this->assigned_to); //have to do this this way because otherwise it errors - return $assigned_to->assetLoc(); // Recurse until we have a final location + if ($assigned_to) { + return $assigned_to->assetLoc(); + } // Recurse until we have a final location } if ($this->assignedType() == self::LOCATION) { - return $this->assignedTo; + if ($this->assignedTo) { + return $this->assignedTo; + } + } if ($this->assignedType() == self::USER) { - if (!$this->assignedTo->userLoc) { - //this makes no sense - return $this->defaultLoc; + if (($this->assignedTo) && $this->assignedTo->userLoc) { + return $this->assignedTo->userLoc; } - return $this->assignedTo->userLoc; + //this makes no sense + return $this->defaultLoc; + } }