Auto Save on live()

Hi all

I want my textfields to automatically save as I type. I thought just adding live() would be enough but I found I needed the following:

TextInput::make('telegram_username')
                                    ->live()
                                    ->afterStateUpdated(function (?TelegramUser $record, Field $component, $state) {
                                        $record->{$component->getName()} = $state;
                                        $record->save();
                                    }),


Is there a better way to do this with less code? I have a page with a lot of fields all needing live saving.

Thanks all,
Was this page helpful?