What seems to be the problem:
I have a lot of properties in my Livewire component, because I have also a lot of fields in my Model. I want that in every properties that has been
updated()
it automatically save it on model. It’s a “save as draft” feature.
The only idea that I have is these:
- Use
updated()
and save all the fields .e.g.:
public function updated()
{
$this->app->$first_name = $this->first_name;
$this->app->$last_name = $this->last_name;
.... etc (+20 fields)
$this->app->save();
}
But the problem of this is that I don’t want to run a whole Eloquent function to just 1 property only.
- Use the
updatedFooBar()
. But it’s not practical since there would be a lot of fields. Imagine, creating 20 of this.
public function updatedFirstName()
{
$this->app->first_name = $this->first_name;
$this->app->save();
}
Is there anyway I can achieve something like:
public function updated($property){
$this->app->$property = $this->$propery;
}