Skip to content

A free open source IT asset/license management system

Adds Lookup Asset by Custom Field via API [sc-18632]

snipeaa3aa78204fc
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php
index b594cb1c95..80a9109ba8 100644
--- a/app/Http/Controllers/Api/AssetsController.php
+++ b/app/Http/Controllers/Api/AssetsController.php
@@ -120,15 +120,24 @@ class AssetsController extends Controller
'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.
- if($filter_non_deprecable_assets) {
+ if ($filter_non_deprecable_assets) {
$non_deprecable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get();
-
$assets->InModelList($non_deprecable_models->toArray());
}
// These are used by the API to query against specific ID numbers.
// They are also used by the individual searches on detail pages like
// locations, etc.
+
+
+ // Search custom fields by column name
+ foreach ($all_custom_fields as $field) {
+ if ($request->filled($field->db_column_name())) {
+ $assets->where($field->db_column_name(), '=', $request->input($field->db_column_name()));
+ }
+ }
+
+
if ($request->filled('status_id')) {
$assets->where('assets.status_id', '=', $request->input('status_id'));
}