A free open source IT asset/license management system
unique undeleted recreated with laravel rule
spencerrlonggd167ec6dc0ec
diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.phpindex 2fb2544160..254895f134 100644--- a/app/Http/Requests/StoreAssetRequest.php+++ b/app/Http/Requests/StoreAssetRequest.php@@ -35,12 +35,6 @@ class StoreAssetRequest extends ImageUploadRequestparent::rules(),);- // unsets unique check here, that check cannot run twice.- $rules['asset_tags.*'] = $rules['asset_tag'];- unset($rules['asset_tag']);- $rules['serials.*'] = $rules['serial'];- unset($rules['serial']);-return $rules;}}diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex 7f4f691628..fac914dcb0 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -100,7 +100,10 @@ class Asset extends Depreciable'expected_checkin' => 'date|nullable','location_id' => 'exists:locations,id|nullable','rtd_location_id' => 'exists:locations,id|nullable',- 'asset_tag' => 'required|min:1|max:255|unique_undeleted',+ // okay, i know this looks scary - but it's not. it checks to see if the asset tag is unique, but only if the asset is not deleted - `NULL,NULL` says to ignore the unique rule if following conditions are met+ // https://laracasts.com/discuss/channels/laravel/unique-validation-with-soft-delete+ // this is tested and verified+ 'asset_tag' => 'required|min:1|max:255|unique:assets,asset_tag,NULL,NULL,deleted_at,NULL','purchase_date' => 'date|date_format:Y-m-d|nullable','serial' => 'unique_serial|nullable','purchase_cost' => 'numeric|nullable|gte:0',