framework icon indicating copy to clipboard operation
framework copied to clipboard

`-ing` Observer events fire after changes are persisted if `ShouldHandleEventsAfterCommit` or `$afterCommit = true` is present

Open WilliamVenner opened this issue 4 months ago • 3 comments

Laravel Version

11.45.1

PHP Version

8.3.8

Database Driver & Version

No response

Description

-ing events such as updating, creating and deleting still fire after the transaction commits if ShouldHandleEventsAfterCommit is implemented or $afterCommit = true property is present on the Observer.

The documentation states that these events fire before changes are persisted, but in the case where ShouldHandleEventsAfterCommit is implemented or $afterCommit = true property is present on the Observer, these events fire after changes are persisted.

I think the documentation should at least clearly clarify this behaviour.

In my opinion -ing events should be excluded from this behaviour entirely. I don't believe there is any logical use case for -ing events to fire this way - it makes them redundant as they effectively just become -ed events.

Steps To Reproduce

  1. Set up an observer for a model that implements ShouldHandleEventsAfterCommit or has $afterCommit = true property
  2. Listen for -ing events
  3. Trigger an -ing event
  4. Inspect the model and notice that changes have been persisted

WilliamVenner avatar Jul 24 '25 15:07 WilliamVenner