From 4100f2600c04604336f122f2ccd0acf7460b53c2 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Nov 2025 20:43:31 +0000 Subject: [PATCH 1/4] Override unique_undeleted in the form request --- app/Http/Requests/UpdateAssetRequest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index 1b379358f9..071134f512 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -28,6 +28,8 @@ class UpdateAssetRequest extends ImageUploadRequest */ public function rules() { + $setting = Setting::getSettings(); + $rules = array_merge( parent::rules(), (new Asset)->getRules(), @@ -37,7 +39,11 @@ class UpdateAssetRequest extends ImageUploadRequest 'status_id' => ['integer', 'exists:status_labels,id'], 'asset_tag' => [ 'min:1', 'max:255', 'not_array', - Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed() + Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed(), + ], + 'serial' => [ + 'nullable', 'string', 'max:255', 'not_array', + $setting->unique_serial=='1' ? Rule::unique('assets', 'serial')->ignore($this->asset)->withoutTrashed() : 'nullable', ], ], ); From 547b3df7b4e7751c4511bd19c59689e510bf508a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Nov 2025 21:08:48 +0000 Subject: [PATCH 2/4] =?UTF-8?q?Added=20more=20commentary=20on=20why=20we?= =?UTF-8?q?=E2=80=99re=20intefering=20with=20the=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Requests/UpdateAssetRequest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index 071134f512..60323c7d3b 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -33,7 +33,9 @@ class UpdateAssetRequest extends ImageUploadRequest $rules = array_merge( parent::rules(), (new Asset)->getRules(), - // this is to overwrite rulesets that include required, and rewrite unique_undeleted + // This overwrites the rulesets that are set at the model level (via Watson) but are not necessarily required at the request level when doing a PATCH update. + // Confusingly, this skips the unique_undeleted validator at the model level (and therefor the UniqueUndeletedTrait), so we have to re-add those + // rules here without the requiredness, since those values will already exist if you're updating an existing asset. [ 'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'], 'status_id' => ['integer', 'exists:status_labels,id'], @@ -42,7 +44,7 @@ class UpdateAssetRequest extends ImageUploadRequest Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed(), ], 'serial' => [ - 'nullable', 'string', 'max:255', 'not_array', + 'string', 'max:255', 'not_array', $setting->unique_serial=='1' ? Rule::unique('assets', 'serial')->ignore($this->asset)->withoutTrashed() : 'nullable', ], ], From e5c55c9ab3cbceaf3f0789ddd53dc38f093e1d6f Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Nov 2025 21:11:54 +0000 Subject: [PATCH 3/4] Fixed typo in the comment --- app/Http/Requests/UpdateAssetRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index 60323c7d3b..912e00a420 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -34,7 +34,7 @@ class UpdateAssetRequest extends ImageUploadRequest parent::rules(), (new Asset)->getRules(), // This overwrites the rulesets that are set at the model level (via Watson) but are not necessarily required at the request level when doing a PATCH update. - // Confusingly, this skips the unique_undeleted validator at the model level (and therefor the UniqueUndeletedTrait), so we have to re-add those + // Confusingly, this skips the unique_undeleted validator at the model level (and therefore the UniqueUndeletedTrait), so we have to re-add those // rules here without the requiredness, since those values will already exist if you're updating an existing asset. [ 'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'], From 4ada47e3b0b60e89a28df2fc7bee94321fe3d301 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Nov 2025 21:12:49 +0000 Subject: [PATCH 4/4] Use new setting variable since we already have it --- app/Http/Requests/UpdateAssetRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index 912e00a420..6d01dc5a30 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -52,7 +52,7 @@ class UpdateAssetRequest extends ImageUploadRequest // if the purchase cost is passed in as a string **and** the digit_separator is ',' (as is common in the EU) // then we tweak the purchase_cost rule to make it a string - if (Setting::getSettings()->digit_separator === '1.234,56' && is_string($this->input('purchase_cost'))) { + if ($setting->digit_separator === '1.234,56' && is_string($this->input('purchase_cost'))) { $rules['purchase_cost'] = ['nullable', 'string']; }