Amiejah
Amiejah
FFilament
Created by Amiejah on 3/26/2024 in #❓┊help
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
2 replies
FFilament
Created by Amiejah on 1/17/2024 in #❓┊help
Custom (profile) page re-using the EditUser (editRecord) resource
I'm trying to create a profile page in which the user can easily manager it's own user information. Instead of creating a custom page, and load the resources forms/tables etc. I wanted it to contain the same configuration as the EditUser resource. Would this be a good way to go?
class Profile extends EditUser { use InteractsWithAuthentication; protected static ?string $navigationIcon = 'heroicon-o-user'; public function mount(int|string|null $record = null): void { $this->record = $this->resolveRecord( static::getUser()->getRouteKey() ); $this->authorizeResourceAccess(); $this->fillForm(); $this->previousUrl = url()->previous(); } public function getBreadcrumbs(): array { return []; } public static function getUrl(array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string { $parameters['tenant'] ??= ($tenant ?? Filament::getTenant()); return route(static::getRouteName($panel), $parameters, $isAbsolute); } /** * This will make sure that the page is registeren while not being part of the (User)Resource * * @param string|null $panel * @return string */ public static function getRouteName(?string $panel = null): string { $panel ??= Filament::getCurrentPanel()->getId(); return (string) str(static::getSlug()) ->replace('/', '.') ->prepend("filament.{$panel}.pages."); } public static function shouldRegisterNavigation(array $parameters = []): bool { return static::getResource()::canEdit( static::getUser() ); } public static function authorizeResourceAccess(): void { abort_unless(static::getResource()::canEdit(static::getUser()), 403); } }
3 replies