diff --git a/README.md b/README.md index 3b03021..457b175 100644 --- a/README.md +++ b/README.md @@ -239,20 +239,40 @@ use Filament\Forms\Form; class MyCustomComponent extends MyProfileComponent { protected string $view = "livewire.my-custom-component"; + public array $only = ['my_custom_field']; + public array $data; + public $user; + public $userClass; - // + // this example shows an additional field we want to capture and save on the user + public function mount() + { + $this->user = Filament::getCurrentPanel()->auth()->user(); + $this->userClass = get_class($this->user); - public array $data; + $this->form->fill($this->user->only($this->only)); + } public function form(Form $form): Form { return $form ->schema([ - TextInput::make('name') + TextInput::make('my_custom_field') ->required() ]) ->statePath('data'); } + + // only capture the custome component field + public function submit(): void + { + $data = collect($this->form->getState())->only($this->only)->all(); + $this->user->update($data); + Notification::make() + ->success() + ->title(__('Custom component updated successfully')) + ->send(); + } } ```