F
Filament10mo ago
Hasith

can i add action button to a stat widget?

I have this widget card. i want to add a button to it and when the user click it I want to delete a record inside the database. Is it possible to add action and how can I do that?
class WarningWidget extends BaseWidget
{
protected static ?int $sort = -2;

protected function getColumns(): int
{
return 1;
}

public static function canView():bool
{

return true;

}

protected function getStats(): array
{
return [

Stat::make('Unknown API Request','')
->description('We are having unknown API request from a unregistered domain')
->icon('heroicon-m-exclamation-triangle')
->color('danger'),

];
}
}
class WarningWidget extends BaseWidget
{
protected static ?int $sort = -2;

protected function getColumns(): int
{
return 1;
}

public static function canView():bool
{

return true;

}

protected function getStats(): array
{
return [

Stat::make('Unknown API Request','')
->description('We are having unknown API request from a unregistered domain')
->icon('heroicon-m-exclamation-triangle')
->color('danger'),

];
}
}
6 Replies
Hugo
Hugo10mo ago
I think you'll have to use a custom component
Hasith
Hasith10mo ago
How i use custom component as a widget? 🤔
Hasith
Hasith10mo ago
Yeah, I can call a function using wire:click. Currently, I'm using this method. Right now it's affecting the whole card. But if I can add a small button inside the Stat card and add action to that button it would be awesome. Such as the Sign Out button on the default Auth widget. @leandro_ferreira
Hasith
Hasith10mo ago
Okay. I will try this and get back here if need help. Thank you ❤️