During this week, the ingenious team behind Laravel unveiled the highly anticipated v10.30 release, packed with an array of exciting features. One of the notable additions is the ability to dispatch events seamlessly, triggered by a database transaction's outcome. This functionality brings further flexibility and control to developers working with Laravel. Additionally, this release encompasses various minor fixes, comprehensive testing, and an assortment of miscellaneous improvements. For a comprehensive overview of all the updates incorporated in this version, I recommend referring to the changelog. https://github.com/laravel/framework/blob/d0a6080db78a7e8a3316ff9c41eb86aa0866742d/CHANGELOG.md

This exceptional contribution introduces the ShouldDispatchAfterCommit interface, which allows you to direct the event dispatcher to defer dispatching the event until the transaction is successfully committed. In the event of a transaction rollback, the event remains dormant and does not trigger.

To elucidate the concept further, envisage the following contrived example showcasing how this functionality might operate—given a transaction and dispatch occurring within the transaction itself:

Here's what the logs might look like:

And finally, the event might look like the following:

Along with ShouldDispatchAfterCommit, the pull request expanded to include other interfaces like ShouldHandleEventsAfterCommit for listeners and ShouldQueueAfterCommit, which may be implemented on jobs, listeners, mail, and notifications.

Reply to this note

Please Login to reply.

Discussion

No replies yet.