Skip to content

Commit 547b3df

Browse files
committed
Added more commentary on why we’re intefering with the request
1 parent 4100f26 commit 547b3df

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app/Http/Requests/UpdateAssetRequest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public function rules()
3333
$rules = array_merge(
3434
parent::rules(),
3535
(new Asset)->getRules(),
36-
// this is to overwrite rulesets that include required, and rewrite unique_undeleted
36+
// 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.
37+
// Confusingly, this skips the unique_undeleted validator at the model level (and therefor the UniqueUndeletedTrait), so we have to re-add those
38+
// rules here without the requiredness, since those values will already exist if you're updating an existing asset.
3739
[
3840
'model_id' => ['integer', 'exists:models,id,deleted_at,NULL', 'not_array'],
3941
'status_id' => ['integer', 'exists:status_labels,id'],
@@ -42,7 +44,7 @@ public function rules()
4244
Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed(),
4345
],
4446
'serial' => [
45-
'nullable', 'string', 'max:255', 'not_array',
47+
'string', 'max:255', 'not_array',
4648
$setting->unique_serial=='1' ? Rule::unique('assets', 'serial')->ignore($this->asset)->withoutTrashed() : 'nullable',
4749
],
4850
],

0 commit comments

Comments
 (0)