'Cannot input data on textbox in Livewire because it resets automatically
I'm trying to make an update function in Laravel Livewire, but whenever I input data on the textbox, the inputted data reset to the data in my database. Still, I want to get new data and update the data on the database. I've tried changing the wire:model in the blade.php, and it receives a new input, but the data cannot be seen in the textbox before the change. Thank you
View/Blade
<div class="mt-4">
<x-jet-label for="first_name" value="{{ __('first name') }}" />
<x-jet-input id="first_name" class="block mt-1 w-full" type="text"
wire:model.debounce.800ms="first_name" required autofocus />
</div>
<x-jet-secondary-button class="ml-2" wire:click="update">
{{ __('Update User') }}
</x-jet-secondary-button>
Controller
public function getUserDataFromDatabase()
{
$this->data = User::find($this->userId);
$this->first_name = $this->data->first_name;
}
public function modelUpdateUser()
{
return [
'first_name' => $this->first_name,
];
}
public function update()
{
User::find($this->userId)->update($this->modelUpdateUser());
$this->resetValidation();
$this->reset();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
