From 7e1b47708e7d44a2ad3bc7af93a38fc2dc6e72a9 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 17 Oct 2024 15:18:41 -0700 Subject: [PATCH] Fix failing test ensuring company id is an integer --- app/Http/Requests/StoreAssetRequest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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, ]); }