| null */ public ?array $data = []; /** * @var ?Model */ #[Locked] public $tenant = null; protected static bool $isDiscovered = false; abstract public static function getLabel(): string; public static function routes(Panel $panel): void { $slug = static::getSlug(); Route::get("/{$slug}", static::class) ->middleware(static::getRouteMiddleware($panel)) ->withoutMiddleware(static::getWithoutRouteMiddleware($panel)) ->name('profile'); } /** * @return string | array */ public static function getRouteMiddleware(Panel $panel): string | array { return [ ...(static::isEmailVerificationRequired($panel) ? [static::getEmailVerifiedMiddleware($panel)] : []), ...static::$routeMiddleware, ]; } public function mount(): void { $this->tenant = Filament::getTenant(); abort_unless(static::canView($this->tenant), 404); $this->fillForm(); } protected function fillForm(): void { $data = $this->tenant->attributesToArray(); $this->callHook('beforeFill'); $data = $this->mutateFormDataBeforeFill($data); $this->form->fill($data); $this->callHook('afterFill'); } /** * @param array $data * @return array */ protected function mutateFormDataBeforeFill(array $data): array { return $data; } /** * @param array $data * @return array */ protected function mutateFormDataBeforeSave(array $data): array { return $data; } public function save(): void { try { $this->callHook('beforeValidate'); $data = $this->form->getState(); $this->callHook('afterValidate'); $data = $this->mutateFormDataBeforeSave($data); $this->callHook('beforeSave'); $this->handleRecordUpdate($this->tenant, $data); $this->callHook('afterSave'); } catch (Halt $exception) { return; } $this->getSavedNotification()?->send(); if ($redirectUrl = $this->getRedirectUrl()) { $this->redirect($redirectUrl); } } /** * @param array $data */ protected function handleRecordUpdate(Model $record, array $data): Model { $record->update($data); return $record; } protected function getSavedNotification(): ?Notification { $title = $this->getSavedNotificationTitle(); if (blank($title)) { return null; } return Notification::make() ->success() ->title($this->getSavedNotificationTitle()); } protected function getSavedNotificationTitle(): ?string { return __('filament-panels::pages/tenancy/edit-tenant-profile.notifications.saved.title'); } protected function getRedirectUrl(): ?string { return null; } public function form(Form $form): Form { return $form; } /** * @return array */ protected function getForms(): array { return [ 'form' => $this->form( $this->makeForm() ->operation('edit') ->model($this->tenant) ->statePath('data'), ), ]; } /** * @return array */ protected function getFormActions(): array { return [ $this->getSaveFormAction(), ]; } protected function getSaveFormAction(): Action { return Action::make('save') ->label(__('filament-panels::pages/tenancy/edit-tenant-profile.form.actions.save.label')) ->submit('save') ->keyBindings(['mod+s']); } public function getTitle(): string | Htmlable { return static::getLabel(); } public static function getSlug(): string { return static::$slug ?? 'profile'; } public static function canView(Model $tenant): bool { try { return authorize('update', $tenant)->allowed(); } catch (AuthorizationException $exception) { return $exception->toResponse()->allowed(); } } }