Make CheckBoxList selected when SELECT field is updated.

I have a select input and a checkboxlist input, I want to use the results of the selected data to fill and check the checkboxlist. HELP!!!
Solution:
Never mind… just changed the set path
Jump to solution
2 Replies
KingNii
KingNiiOP7mo ago
Select::make('roles')
->label('Roles')
->options(Role::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Set $set, Get $get, ?string $state) {
// dd($state);
$role = Role::findOrFail($state);
// dd($role->permissions->pluck('name', 'id'));
// dd($set('../permission', $role->permissions->pluck('name', 'id')));
// dd( Role::whereId($state)->permission());
$set('../permission', $role->permissions->pluck('name', 'id'));
})
->columnSpanFull()
->searchable(),
CheckboxList::make('permission')
->label('Permission')
->required()
// ->options(Permission::all()->pluck('name', 'id'))
->columns([
'sm' => 2,
'md' => 4
])
])->statePath('editRole');
Select::make('roles')
->label('Roles')
->options(Role::all()->pluck('name', 'id'))
->live()
->afterStateUpdated(function (Set $set, Get $get, ?string $state) {
// dd($state);
$role = Role::findOrFail($state);
// dd($role->permissions->pluck('name', 'id'));
// dd($set('../permission', $role->permissions->pluck('name', 'id')));
// dd( Role::whereId($state)->permission());
$set('../permission', $role->permissions->pluck('name', 'id'));
})
->columnSpanFull()
->searchable(),
CheckboxList::make('permission')
->label('Permission')
->required()
// ->options(Permission::all()->pluck('name', 'id'))
->columns([
'sm' => 2,
'md' => 4
])
])->statePath('editRole');
Solution
KingNii
KingNii7mo ago
Never mind… just changed the set path
Want results from more Discord servers?
Add your server