F
Filament2y ago
Xavi

Action call livewire method

On table action, is it possible to call livewire method? Thankyou so much!
4 Replies
Xavi
XaviOP2y ago
i try to doit like this
protected function getTableActions(): array
{
return [
Action::make(ucfirst(__('messages.activate')))
->action(fn (Location $record): string => 'activate')
->requiresConfirmation()
->hidden(function (Location $record) {
return $record->managed;
})
->modalHeading(ucfirst(__('messages.activate_location_heading')))
->modalSubheading(ucfirst(__('messages.activate_location_subheading')))
->modalButton(ucfirst(__('messages.activate_location_yes'))),
];
}

public function activate(Location $location)
{
dd($location);
//$location->update(['managed' => true]);
}
protected function getTableActions(): array
{
return [
Action::make(ucfirst(__('messages.activate')))
->action(fn (Location $record): string => 'activate')
->requiresConfirmation()
->hidden(function (Location $record) {
return $record->managed;
})
->modalHeading(ucfirst(__('messages.activate_location_heading')))
->modalSubheading(ucfirst(__('messages.activate_location_subheading')))
->modalButton(ucfirst(__('messages.activate_location_yes'))),
];
}

public function activate(Location $location)
{
dd($location);
//$location->update(['managed' => true]);
}
but it doesnt call activate method
Sebastiaan
Sebastiaan2y ago
Returning the string won't work You should just call the method from the ->action closure on the Action
Xavi
XaviOP2y ago
with $this->method() ??
Dan Harrin
Dan Harrin2y ago
action(‘activate’) or action(fn ($livewire, $record) => $livewire->activate($record))

Did you find this page helpful?