mirror of
https://github.com/snipe/snipe-it.git
synced 2024-09-20 07:47:41 -07:00
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
This commit is contained in:
parent
b2469bb34f
commit
f786e07179
|
@ -344,7 +344,7 @@ class AssetsController extends Controller
|
||||||
$asset->model_id = $request->get('model_id');
|
$asset->model_id = $request->get('model_id');
|
||||||
$asset->order_number = $request->get('order_number');
|
$asset->order_number = $request->get('order_number');
|
||||||
$asset->notes = $request->get('notes');
|
$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->user_id = Auth::id();
|
||||||
$asset->archived = '0';
|
$asset->archived = '0';
|
||||||
$asset->physical = '1';
|
$asset->physical = '1';
|
||||||
|
|
|
@ -36,13 +36,16 @@ class AssetRequest extends Request
|
||||||
'checkin_date' => 'date',
|
'checkin_date' => 'date',
|
||||||
'supplier_id' => 'integer|nullable',
|
'supplier_id' => 'integer|nullable',
|
||||||
'status' => 'integer|nullable',
|
'status' => 'integer|nullable',
|
||||||
'asset_tag' => 'required',
|
|
||||||
'purchase_cost' => 'numeric|nullable',
|
'purchase_cost' => 'numeric|nullable',
|
||||||
"assigned_user" => 'sometimes:required_without_all:assigned_asset,assigned_location',
|
"assigned_user" => 'sometimes:required_without_all:assigned_asset,assigned_location',
|
||||||
"assigned_asset" => 'sometimes:required_without_all:assigned_user,assigned_location',
|
"assigned_asset" => 'sometimes:required_without_all:assigned_user,assigned_location',
|
||||||
"assigned_location" => 'sometimes:required_without_all:assigned_user,assigned_asset',
|
"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'));
|
$model = AssetModel::find($this->request->get('model_id'));
|
||||||
|
|
||||||
if (($model) && ($model->fieldset)) {
|
if (($model) && ($model->fieldset)) {
|
||||||
|
|
Loading…
Reference in a new issue