So I've been working across a few different languages and frameworks recently and I've found that outside of Laravel, it's actually quite common to have a single database transaction (at least for writes) per request.
When using Doctrine, you'd persist things to the EntityManager but it's rare to see implementations that flush until the full request is completed. So all changes are committed in the same transaction.
In a Go framework I've been working with, they actually have a database transaction middleware that starts a transaction per request, then commits at the end of the request. This seems like an easy way to prevent an inconsistent state in the application, especially with unexpected exceptions.
Has anyone implemented this in Laravel? Any thoughts on this approach?
Implementation seems like it'd be pretty easy especially if the app only has one database. And you could always manually flush (commit and open a new transaction) if the need arises inside your app.