Laravel Nova - Observer Update Method Causes 502

752 views Asked by At

When trying to update a resource in Laravel Nova that has a Observer the update loads for a while and then ends with a 502 error. The observer is registered correctly (the created method works fine) and I'm not trying to do anything special in the updated method. Any ideas?

 public function updated(Model $model)
    {
        //
        $model->title = 'test';
        $model->save();
        
    }

If I try this without the $model->save(), there is no 502 error but the change I want to happen also doesn't happen. I get the green success message, and any change I make on the form prior to updating occurs, but not the change I'm trying to make during the updated method.

Any help troubleshooting this would be appreciated

1

There are 1 answers

0
Luke On

I am not very good at Laravel, but I think, that you should to try this:

In your model file add method:

    public function saveQuietly(array $options = [])
{
    return static::withoutEvents(function () use ($options) {
       return $this->save($options);
});
}

Then, in your updated method in observer do something like this:

public function updated(Model $model)
{
$model->title = 'test';
 
$model->saveQuietly();
        
}