afterStateUpdated doesn't work
Here's my resource to manage permissions using spatie library:
return $table
->columns([
TextColumn::make('name')
->label('Permission\Role')
->sortable()
->searchable(),
...Role::all()->map(fn($role) => CheckboxColumn::make('role_' . $role->id)
->label($role->name)
->getStateUsing(fn ($record) => $record->roles->contains($role))
->toggleable()
->afterStateUpdated(function ($state, $record) use ($role) {
DB::transaction(function () use ($state, $record, $role) {
if ($state) {
$role->givePermissionTo($record);
} else {
$role->revokePermissionTo($record);
}
});
}))->toArray(),
])
For some reason, when i change checkbox state, it still trying to update a column in Permissions table instead of do what my callback do.
I'm new in fillament, so I would appreciate any help
1 Reply
try
updateStateUsing