Skip to content

Commit 1ef336a

Browse files
authored
Merge pull request #10576 from snipe/features/add_custom_fields_search
Added #9576 - Lookup Asset by Custom Field via API [sc-18632]
2 parents db0a078 + aa3aa78 commit 1ef336a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

app/Http/Controllers/Api/AssetsController.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,24 @@ public function index(Request $request, $audit = null)
120120
'model.category', 'model.manufacturer', 'model.fieldset','supplier'); //it might be tempting to add 'assetlog' here, but don't. It blows up update-heavy users.
121121

122122

123-
if($filter_non_deprecable_assets) {
123+
if ($filter_non_deprecable_assets) {
124124
$non_deprecable_models = AssetModel::select('id')->whereNotNull('depreciation_id')->get();
125-
126125
$assets->InModelList($non_deprecable_models->toArray());
127126
}
128127

129128
// These are used by the API to query against specific ID numbers.
130129
// They are also used by the individual searches on detail pages like
131130
// locations, etc.
131+
132+
133+
// Search custom fields by column name
134+
foreach ($all_custom_fields as $field) {
135+
if ($request->filled($field->db_column_name())) {
136+
$assets->where($field->db_column_name(), '=', $request->input($field->db_column_name()));
137+
}
138+
}
139+
140+
132141
if ($request->filled('status_id')) {
133142
$assets->where('assets.status_id', '=', $request->input('status_id'));
134143
}

0 commit comments

Comments
 (0)