From 1122562b4eba27e49a9f5109dc6b4a74e4316c98 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Nov 2022 17:45:50 +0000 Subject: [PATCH 1/2] Handle use case where there are no custom fields for any assigned models Signed-off-by: snipe --- app/Http/Controllers/ViewAssetsController.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 55499ab22..7f5343ede 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -38,14 +38,19 @@ class ViewAssetsController extends Controller 'licenses', )->find(Auth::user()->id); + $field_array = array(); + // Loop through all the custom fields that are applied to any model the user has assigned foreach ($user->assets as $asset) { - foreach ($asset->model->fieldset->fields as $field) { - // check and make sure they're allowed to see the value of the custom field - if ($field->display_in_user_view == '1') { - $field_array[$field->db_column] = $field->name; + if ($asset->model->fieldset) { + foreach ($asset->model->fieldset->fields as $field) { + // check and make sure they're allowed to see the value of the custom field + if ($field->display_in_user_view == '1') { + $field_array[$field->db_column] = $field->name; + } } } + } // Since some models may re-use the same fieldsets/fields, let's make the array unique so we don't repeat columns From 489895a5fa8afd79158f63a72794bb047ef76542 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 16 Nov 2022 17:48:28 +0000 Subject: [PATCH 2/2] Added comments and spacing for readability Signed-off-by: snipe --- app/Http/Controllers/ViewAssetsController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 7f5343ede..ee3e4b14c 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -42,12 +42,16 @@ class ViewAssetsController extends Controller // Loop through all the custom fields that are applied to any model the user has assigned foreach ($user->assets as $asset) { + + // Make sure the model has a custom fieldset before trying to loop through the associated fields if ($asset->model->fieldset) { + foreach ($asset->model->fieldset->fields as $field) { // check and make sure they're allowed to see the value of the custom field if ($field->display_in_user_view == '1') { $field_array[$field->db_column] = $field->name; } + } }