From f13c1a53eff338297d68e81b6aaa233220778420 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 19 Dec 2023 12:51:35 +0000 Subject: [PATCH 1/2] Get an object instead of a collection Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 79e55befb9..6a737b267e 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -574,8 +574,8 @@ class AssetsController extends Controller $asset = $request->handleImages($asset); // Update custom fields in the database. - // Validation for these fields is handled through the AssetRequest form request - $model = AssetModel::find($request->get('model_id')); + // Sometimes people send arrays to this. They shouldn't, but they do, so we use "first()" to get the first match + $model = AssetModel::where('id', '=', $request->get('model_id'))->first(); if (($model) && ($model->fieldset)) { foreach ($model->fieldset->fields as $field) { From f9139e0f101c06e5310b5b072329d96185ddc73b Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 19 Dec 2023 13:25:32 +0000 Subject: [PATCH 2/2] Changed to use instanceof Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 6a737b267e..0947aaba5e 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -574,10 +574,11 @@ class AssetsController extends Controller $asset = $request->handleImages($asset); // Update custom fields in the database. - // Sometimes people send arrays to this. They shouldn't, but they do, so we use "first()" to get the first match - $model = AssetModel::where('id', '=', $request->get('model_id'))->first(); + $model = AssetModel::find($request->input('model_id')); - if (($model) && ($model->fieldset)) { + // Check that it's an object and not a collection + // (Sometimes people send arrays here and they shouldn't + if (($model) && ($model instanceof AssetModel) && ($model->fieldset)) { foreach ($model->fieldset->fields as $field) { // Set the field value based on what was sent in the request