Skip to content

Commit

Permalink
Added default field info to models API response
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>
  • Loading branch information
snipe committed Jan 5, 2023
1 parent ace73ac commit db43628
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/Http/Transformers/AssetModelsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ public function transformAssetModels(Collection $assetmodels, $total)

public function transformAssetModel(AssetModel $assetmodel)
{

$default_field_values = array();

// Reach into the custom fields and models_custom_fields pivot table to find the default values for this model
if ($assetmodel->fieldset) {
foreach($assetmodel->fieldset->fields AS $field) {
$default_field_values[] = [
'name' => e($field->name),
'db_column_name' => e($field->db_column_name()),
'default_value' => ($field->defaultValue($assetmodel->id)) ? e($field->defaultValue($assetmodel->id)) : null,
'required' => ($field->pivot->required == '1') ? true : false,
];
}
}

$array = [
'id' => (int) $assetmodel->id,
'name' => e($assetmodel->name),
Expand All @@ -44,6 +59,7 @@ public function transformAssetModel(AssetModel $assetmodel)
'id' => (int) $assetmodel->fieldset->id,
'name'=> e($assetmodel->fieldset->name),
] : null,
'default_fieldset_values' => $default_field_values,
'eol' => ($assetmodel->eol > 0) ? $assetmodel->eol.' months' : 'None',
'requestable' => ($assetmodel->requestable == '1') ? true : false,
'notes' => e($assetmodel->notes),
Expand Down

0 comments on commit db43628

Please sign in to comment.