From f786e0717930103c58de90ba8b356ca27061a7da Mon Sep 17 00:00:00 2001 From: Brandon Daniel Bailey Date: Wed, 3 Jan 2018 18:24:32 -0700 Subject: [PATCH] Allow auto increment through the API (#4690) * Allow auto incrementing asset_id from the API when the setting is enabled * Cleaned up the if else statement * Added prefix to the orWhereRaw which causes a database error if the configuration uses a prefix * Auto incrementing through the API --- app/Http/Controllers/Api/AssetsController.php | 2 +- app/Http/Requests/AssetRequest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 00ad29da2f..be49a30f00 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -344,7 +344,7 @@ class AssetsController extends Controller $asset->model_id = $request->get('model_id'); $asset->order_number = $request->get('order_number'); $asset->notes = $request->get('notes'); - $asset->asset_tag = $request->get('asset_tag'); + $asset->asset_tag = $request->get('asset_tag', Asset::autoincrement_asset()); $asset->user_id = Auth::id(); $asset->archived = '0'; $asset->physical = '1'; diff --git a/app/Http/Requests/AssetRequest.php b/app/Http/Requests/AssetRequest.php index 7b29b51e7c..921b28ad15 100644 --- a/app/Http/Requests/AssetRequest.php +++ b/app/Http/Requests/AssetRequest.php @@ -36,13 +36,16 @@ class AssetRequest extends Request 'checkin_date' => 'date', 'supplier_id' => 'integer|nullable', 'status' => 'integer|nullable', - 'asset_tag' => 'required', 'purchase_cost' => 'numeric|nullable', "assigned_user" => 'sometimes:required_without_all:assigned_asset,assigned_location', "assigned_asset" => 'sometimes:required_without_all:assigned_user,assigned_location', "assigned_location" => 'sometimes:required_without_all:assigned_user,assigned_asset', ]; + $settings = \App\Models\Setting::getSettings(); + + $rules['asset_tag'] = ($settings->auto_increment_assets == '1') ? 'max:255' : 'required'; + $model = AssetModel::find($this->request->get('model_id')); if (($model) && ($model->fieldset)) {