phplaravel

Laravel Eloquent ORM Transactions


The Eloquent ORM is quite nice, though I'm wondering if there is an easy way to setup MySQL transactions using innoDB in the same fashion as PDO, or if I would have to extend the ORM to make this possible?


Solution

  • You can do this:

    DB::transaction(function() {
          //
    });
    

    Everything inside the Closure executes within a transaction. If an exception occurs it will rollback automatically.