Skip to content

A free open source IT asset/license management system

Fix failing test ensuring company id is an integer

Marcus Moore7e1b47708e7d
diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php
index 26d01051b4..e1665e2136 100644
--- a/app/Http/Requests/StoreAssetRequest.php
+++ b/app/Http/Requests/StoreAssetRequest.php
@@ -26,11 +26,18 @@ class StoreAssetRequest extends ImageUploadRequest
public function prepareForValidation(): void
{
+ // Guard against users passing in an array for company_id instead of an integer.
+ // If the company_id is not an integer then we simply use what was
+ // provided to be caught by model level validation later.
+ $idForCurrentUser = is_int($this->company_id)
+ ? Company::getIdForCurrentUser($this->company_id)
+ : $this->company_id;
+
$this->parseLastAuditDate();
$this->merge([
'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(),
- 'company_id' => Company::getIdForCurrentUser($this->company_id),
+ 'company_id' => $idForCurrentUser,
'assigned_to' => $assigned_to ?? null,
]);
}