Unit Of Work Pattern for Eloquent #52595
Unanswered
michael-rubel
asked this question in
Ideas
Replies: 1 comment 4 replies
-
Hi. What brings this new to the table vs Eloquent's db transactions and nested transactions? I am just curious, this is not a rhetorical question. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know if this topic was discussed in the community previously, but I came across the idea of implementing the class that will handle my Eloquent IUD operations following Martin Fowler's Unit Of Work pattern and native Laravel database transactions.
For example:
The same can be registered for updates and deletes. It's essentially how Doctrine works in the Symfony world:
Every database operation gets queued (and no SQL queries get executed immediately), then if any of the interactions fail during the
commit
process, everything rolls back, and the data stays consistent no matter "at which stage" it failed.I've written a basic implementation of the Unit Of Work as a separate class, so it's not affecting Eloquent internally and is fully optional to use. Do you think this topic is worth digging deeper and potentially contributing to the framework? Personally, I see this as a huge benefit. Symfony guys love Doctrine exactly because of this behavior by default. I always wanted to have this in Laravel at least optionally, but supported natively.
Beta Was this translation helpful? Give feedback.
All reactions