Logout action in a livewire component

I'm using the actions as a Livewire component to display a Sidepanel. However trying to figure out on how to create a "logout" action. I'm thinking of setting an extraAttribute (onClick) which will trigger a JS function to submit a form (logout form). Something like this:
public function displayMenu(): Action
{
return Action::make('submit')
->icon('heroicon-o-bars-3')
->iconButton()
->size(ActionSize::ExtraLarge)
->modalSubmitAction(false)
->modalCancelAction(false)
->registerModalActions([
Action::make('logout')
->icon('far-arrow-right-from-bracket')
->label(__('Sign out'))
->link()
->extraAttributes(['onclick' => 'logout()']),
])
->modalHeading(fn () => new HtmlString(
view('steponthebox.layouts::modal-heading',
[
'logo' => filament()->getBrandLogo(),
]))
)
->modalContent(fn (Action $action) => view(
'layouts::menu-items',
[
'menuItems' => new HtmlString($this->items),
'action' => $action
]
))
->modalWidth(MaxWidth::Small)
->slideOver();
}
public function displayMenu(): Action
{
return Action::make('submit')
->icon('heroicon-o-bars-3')
->iconButton()
->size(ActionSize::ExtraLarge)
->modalSubmitAction(false)
->modalCancelAction(false)
->registerModalActions([
Action::make('logout')
->icon('far-arrow-right-from-bracket')
->label(__('Sign out'))
->link()
->extraAttributes(['onclick' => 'logout()']),
])
->modalHeading(fn () => new HtmlString(
view('steponthebox.layouts::modal-heading',
[
'logo' => filament()->getBrandLogo(),
]))
)
->modalContent(fn (Action $action) => view(
'layouts::menu-items',
[
'menuItems' => new HtmlString($this->items),
'action' => $action
]
))
->modalWidth(MaxWidth::Small)
->slideOver();
}
Is there no better option than this? Thank you
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server