A free open source IT asset/license management system
tested, working
spencerrlonggc7f90ad86d05
diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.phpindex 4216cf7cb0..254895f134 100644--- a/app/Http/Requests/StoreAssetRequest.php+++ b/app/Http/Requests/StoreAssetRequest.php@@ -35,9 +35,6 @@ class StoreAssetRequest extends ImageUploadRequestparent::rules(),);- // temporary fix for unique serials- unset($rules['serial']);-return $rules;}}diff --git a/app/Http/Traits/UniqueSerialTrait.php b/app/Http/Traits/UniqueSerialTrait.phpdeleted file mode 100644index b5529d7cf8..0000000000--- a/app/Http/Traits/UniqueSerialTrait.php+++ /dev/null@@ -1,25 +0,0 @@-<?php--namespace App\Http\Traits;--use App\Models\Setting;--trait UniqueSerialTrait-{- /**- * Prepare a unique_ids rule, adding a model identifier if required.- *- * @param array $parameters- * @param string $field- *- * @return string- */- protected function prepareUniqueSerialRule($parameters, $field)- {- if ($settings = Setting::getSettings()) {- if ($settings->unique_serial == '1') {- return 'unique_undeleted:'.$this->table.','.$this->getKey();- }- }- }-}diff --git a/app/Models/Asset.php b/app/Models/Asset.phpindex a7d4d7442a..ea436f0138 100644--- a/app/Models/Asset.php+++ b/app/Models/Asset.php@@ -6,7 +6,6 @@ use App\Events\AssetCheckedOut;use App\Events\CheckoutableCheckedOut;use App\Exceptions\CheckoutNotAllowed;use App\Helpers\Helper;-use App\Http\Traits\UniqueSerialTrait;use App\Http\Traits\UniqueUndeletedTrait;use App\Models\Traits\Acceptable;use App\Models\Traits\Searchable;@@ -32,7 +31,7 @@ class Asset extends Depreciableprotected $presenter = \App\Presenters\AssetPresenter::class;use CompanyableTrait;- use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait, UniqueSerialTrait;+ use HasFactory, Loggable, Requestable, Presentable, SoftDeletes, ValidatingTrait, UniqueUndeletedTrait;public const LOCATION = 'location';public const ASSET = 'asset';@@ -100,7 +99,7 @@ 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:assets,asset_tag',+ 'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag|not_array','purchase_date' => 'date|date_format:Y-m-d|nullable','serial' => 'unique_serial|nullable','purchase_cost' => 'numeric|nullable|gte:0',diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.phpindex 30c5a0197e..37866208d4 100644--- a/app/Providers/ValidationServiceProvider.php+++ b/app/Providers/ValidationServiceProvider.php@@ -2,7 +2,9 @@namespace App\Providers;+use App\Models\Asset;use App\Models\Department;+use App\Models\Setting;use DB;use Illuminate\Support\ServiceProvider;use Illuminate\Validation\Rule;@@ -72,6 +74,17 @@ class ValidationServiceProvider extends ServiceProvider}});++ Validator::extend('unique_serial', function ($attribute, $value, $parameters, $validator) {+ if(Setting::getSettings()->unique_serial == '1') {+ $count = DB::table('assets')->select('id')->where('serial', '=', $value)->whereNull('deleted_at')->count();++ return $count < 1;+ } else {+ return true;+ }+ });+// Prevent circular references//// Example usage in Location model where parent_id references another Location:diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.phpindex bb35515fdb..85e8447812 100644--- a/resources/lang/en/validation.php+++ b/resources/lang/en/validation.php@@ -96,6 +96,7 @@ return ['unique_undeleted' => 'The :attribute must be unique.','non_circular' => 'The :attribute must not create a circular reference.','not_array' => 'The :attribute field cannot be an array.',+ 'unique_serial' => 'The :attribute must be unique.','disallow_same_pwd_as_user_fields' => 'Password cannot be the same as the username.','letters' => 'Password must contain at least one letter.','numbers' => 'Password must contain at least one number.',