You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can reorder and move from one parent to another parent for an item from listing view, but having trouble to update parent_id for particular item from edit form.
Declaring a Select Field for parent in Controller.
public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);
$form->add(
Select::make()->name('parent_id')->label('Parent Menu')
->options(
Sitemenu::all()->mapWithKeys(function ($sitemenu) {
return [$sitemenu->id => $sitemenu->title];
})->prepend('None', '')->toArray()
)
);
And having a afterSave function In Repository.php.
we found that $fields['parent_id'] field alway return last saved value ONLY
If last saved was 5, it will always return 5, no matter what you chose from the Select Dropdown which named it as "parent_id"
Select::make()->name('parent_id')
public function afterSave($model, $fields): void
{
if (isset($fields['parent_id'])) {
$model->parent_id = $fields['parent_id'] ?: null; // Set null if empty
}
$model->save();
parent::afterSave($model, $fields);
}
Not sure how can update Parent Level from Form, any idea?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I can reorder and move from one parent to another parent for an item from listing view, but having trouble to update parent_id for particular item from edit form.
Declaring a Select Field for parent in Controller.
And having a afterSave function In Repository.php.
we found that $fields['parent_id'] field alway return last saved value ONLY
If last saved was 5, it will always return 5, no matter what you chose from the Select Dropdown which named it as "parent_id"
Select::make()->name('parent_id')
Not sure how can update Parent Level from Form, any idea?
Beta Was this translation helpful? Give feedback.
All reactions