framework icon indicating copy to clipboard operation
framework copied to clipboard

Observer attribute changes ignored when using increment()

Open eNzyOfficial opened this issue 2 years ago • 1 comments

  • Laravel Version: 9 (latest)
  • PHP Version: 8.2 (latest)
  • Database Driver & Version: Mysql 8 (latest)

Description:

When using increment(), it is not possible to have an Observer update any other values.

Not sure if this is intentional but if it is, it might be worth putting it as a caveat in the docs because I wasted quite a bit of time trying to work out what the problem was.

Steps To Reproduce:

$model->increment('column');

then in the observer:

public function updating($model): void
{
        $model->another_column = 'example';
}

The another_column while it gets set in the Model instance, it isn't propagated in the database.

eNzyOfficial avatar Dec 02 '22 08:12 eNzyOfficial

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

github-actions[bot] avatar Dec 02 '22 10:12 github-actions[bot]

Looks like we won't change this behavior, sorry.

driesvints avatar Dec 08 '22 12:12 driesvints

Looking at the PR, it seems like Taylor doesn't want to make the change in a patch release, how about adding it to the Laravel 10 release?

If no plans to fix this at all, maybe it's worth adding this caveat to the documentation.

Thanks anyway, take care

eNzyOfficial avatar Dec 09 '22 02:12 eNzyOfficial