When doing multiple database operations in a single http request, command line, method,…
we often need to use a database transaction to keep data safe.
Example in an Action of a Controller
A better choice
- Add a method that allows you to keep your code DRY.
- This method gets a
callable param (a function/method to execute) and deals with potential exceptions, and transaction
- It’s a really dead simple example and a reminder, feel free to improve it.
- You could also move it into a service for instance.