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); } }
1 Reply
Amiejah
Amiejah5mo ago
btw this code seems to work, but I just want to make sure that it's a "clean wway" to create a page like this?