| null */ public ?array $data = []; public function mount(): void { $this->fillForm(); } public function getUser(): Authenticatable | Model { $user = Filament::auth()->user(); if (! $user instanceof Model) { throw new RuntimeException('The authenticated user object must be an Eloquent model to allow profile information to be updated.'); } return $user; } public function fillForm(): void { $data = $this->getUser()->withoutRelations()->toArray(); $data = $this->mutateFormDataBeforeFill($data); $this->form->fill($data); } /** * @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 { $data = $this->form->getState(); $data = $this->mutateFormDataBeforeSave($data); $this->handleRecordUpdate($this->getUser(), $data); } catch (Halt $exception) { return; } $this->getSavedNotification()?->send(); $this->fillForm(); } /** * @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()) ->body($this->getSavedNotificationBody()); } protected function getSavedNotificationTitle(): ?string { return __('filament-companies::default.notifications.profile_information_updated.title'); } protected function getSavedNotificationBody(): ?string { return __('filament-companies::default.notifications.profile_information_updated.body'); } public function form(Form $form): Form { return $form ->schema([ Forms\Components\FileUpload::make('profile_photo_path') ->label('Photo') ->avatar() ->extraAttributes([ 'style' => 'width: 6rem; height: 6rem;', ]) ->placeholder(static function () { return new HtmlString('
' . Blade::render('') . '
'); }) ->disk(FilamentCompanies::profilePhotoDisk()) ->directory(FilamentCompanies::profilePhotoStoragePath()) ->saveUploadedFileUsing(function (User $record, UploadedFile $file) { $record->updateProfilePhoto($file); }) ->deleteUploadedFileUsing(function (User $record) { $record->deleteProfilePhoto(); }) ->image() ->nullable(), Forms\Components\TextInput::make('name') ->label(__('Name')) ->required() ->maxLength(255) ->autofocus(), Forms\Components\TextInput::make('email') ->label(__('Email')) ->email() ->required() ->autocomplete('username') ->maxLength(255) ->unique(ignoreRecord: true), ]) ->operation('edit') ->model($this->getUser()) ->statePath('data'); } public function render(): View { return view('livewire.update-profile-information'); } }