framework
framework copied to clipboard
Observer attribute changes ignored when using increment()
- 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.
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!
Looks like we won't change this behavior, sorry.
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