Enhancing Laravel: Streamlining Database Transactions to Uphold DRY Principles #49885
Replies: 2 comments 4 replies
-
DRY does not mean that your repeating function calls are considered duplicate code. So why the above code should be considered duplicate code? |
Beta Was this translation helpful? Give feedback.
-
Providing that there is no significant performance hit by doing so, would it make sense for Laravel by default to start a database transaction the first time there is an update (or on the first database request) and do a commit when Laravel terminates normally and a rollback when Laravel terminates abnormally (through an exception or a non 200 return code)? Since it is easy to come up with situations where you would want manual control of transactions, you would need some way for the App to turn off this functionality. And for existing code with manual transactions you would want it to play nice without any code changes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In the Laravel ecosystem, the ethos of Don't Repeat Yourself (DRY) is a guiding principle for efficient and maintainable code. However, when it comes to managing database transactions, developers often find themselves duplicating code by repeatedly implementing transaction handling mechanisms like
DB::beginTransaction()
,DB::rollBack()
, andDB::commit()
throughout their projects orThis discussion aims to explore avenues within Laravel for streamlining database transactions to better adhere to the DRY principle. By identifying common patterns and pain points in transaction management, we can brainstorm potential enhancements or features that Laravel could incorporate to automate and simplify transaction handling.
Beta Was this translation helpful? Give feedback.
All reactions