Laravel Eloquent ORM Transactions

后端 未结 7 2163
闹比i
闹比i 2020-12-22 17:30

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 exte

7条回答
  •  庸人自扰
    2020-12-22 17:58

    I'm Sure you are not looking for a closure solution, try this for a more compact solution

     try{
        DB::beginTransaction();
    
        /*
         * Your DB code
         * */
    
        DB::commit();
    }catch(\Exception $e){
        DB::rollback();
    }
    

提交回复
热议问题