Field not updating in database, but shows successful update

Why wouldn't this field be getting updated in the database?
public function form(Form $form): Form
{
return $form
->schema([
FieldSet::make()->relationship('config')->schema([
Select::make('field_id')
->options($this->accounts)
->live()
->reactive()
->preload()
->searchable()
->loadingMessage('Loading accounts...')
->afterStateUpdated(function (string $state, LocationConfig $config) {
$config->update(['field_id' => $state]);
}),
])->statePath('data')
->model($this->location);
}
public function form(Form $form): Form
{
return $form
->schema([
FieldSet::make()->relationship('config')->schema([
Select::make('field_id')
->options($this->accounts)
->live()
->reactive()
->preload()
->searchable()
->loadingMessage('Loading accounts...')
->afterStateUpdated(function (string $state, LocationConfig $config) {
$config->update(['field_id' => $state]);
}),
])->statePath('data')
->model($this->location);
}
The update is being sent to the server and shows a 200 response, but the database isn't updated. I don't know if it has to do with the relationship. The location has a related config model where the field lives. I can DD the $config inside the afterStateUpdated method and it's showing the config model. It seems like it should be automatically updating the field without having to do the afterStateUpdated thing, but even with that it's not updating the database.
5 Replies
Tim van Heugten
Tim van Heugten5mo ago
Just checking, is the field in the fillable array of your model?
Jon Mason
Jon Mason5mo ago
I have my models unguarded, but I just added the fillable array just to test it and it's still not working.
toeknee
toeknee5mo ago
I had this once too. Are you filling on the mount? And finally. try as a test: $this->form->model($this->location)->saveRelationships(); within save function? This worked for me prior to having my form booted correctly.
Jon Mason
Jon Mason5mo ago
I am running $this->form->fill() in my mount method. Do you just mean like this:
->afterStateUpdated(function (string $state, LocationConfig $config) {
$config->update(['field_id' => $state]);
$this->form->model($this->location)->saveRelationships();
}),
->afterStateUpdated(function (string $state, LocationConfig $config) {
$config->update(['field_id' => $state]);
$this->form->model($this->location)->saveRelationships();
}),
That's not having any effect either. Was trying to have it just save automatically, but maybe I just need to add a save button and move on... If I attach the whole file, is someone willing to take a look and see if I'm missing something? I feel like this should be pretty straight-forward.
toeknee
toeknee5mo ago
Can you put the resource and models etc in a git so we can pull it down and test