Reputation: 379
In Backpack CMS framework I have created a table using migration fields like : 'parent_id' and 'is_active'. I have added these fields in the crud controller using the following command:
$this->crud->addFields(array(
['name' => 'title',
'label' => 'Title',
'type'=>'text'],
['name' => 'parent_id',
'label' => 'Parent ID',
'type'=> 'number'],
['name' => 'is_active',
'label' => 'Is Active',
'type'=>'number']
), 'update/create/both');
It should work in edit mode and create mode like my other tables. It shows the defined fields in the create and update form but unfortunately they doesn't work and always return the default value or previous value in the record. I've tried adding the field in single format but there was no use.
Upvotes: 0
Views: 617
Reputation: 379
The problem was with the fillable variable..... Only the 'title' field was in the fillable variable of the related model.
Upvotes: 1
Reputation: 10117
The problem is here: 'update/create/both'
you should pick only one of the three options.
What you want is to use only both
. But since it is the default value, you don't really need to add it to the end of the addFields
function.
This will work:
$this->crud->addFields([[
'name' => 'title',
'label' => 'Title',
'type' => 'text'
], [
'name' => 'parent_id',
'label' => 'Parent ID',
'type' => 'number'
], [
'name' => 'is_active',
'label' => 'Is Active',
'type' => 'number'
]
]);
Upvotes: 1