Handle use case where there are no custom fields for any assigned models

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2022-11-16 17:45:50 +00:00
parent 4ffe13d3c2
commit 1122562b4e

View file

@ -38,14 +38,19 @@ class ViewAssetsController extends Controller
'licenses', 'licenses',
)->find(Auth::user()->id); )->find(Auth::user()->id);
$field_array = array();
// Loop through all the custom fields that are applied to any model the user has assigned // Loop through all the custom fields that are applied to any model the user has assigned
foreach ($user->assets as $asset) { foreach ($user->assets as $asset) {
foreach ($asset->model->fieldset->fields as $field) { if ($asset->model->fieldset) {
// check and make sure they're allowed to see the value of the custom field foreach ($asset->model->fieldset->fields as $field) {
if ($field->display_in_user_view == '1') { // check and make sure they're allowed to see the value of the custom field
$field_array[$field->db_column] = $field->name; 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 // Since some models may re-use the same fieldsets/fields, let's make the array unique so we don't repeat columns