Laravel雄辩的ORM交易 [英] Laravel Eloquent ORM Transactions

查看:62
本文介绍了Laravel雄辩的ORM交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

雄辩的ORM很好,尽管我想知道是否有一种简便的方法可以以与PDO相同的方式使用innoDB设置MySQL事务,或者是否必须扩展ORM才能实现这一点?

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?

推荐答案

您可以执行以下操作:

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

关闭过程中的所有操作都在事务中执行.如果发生异常,它将自动回滚.

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

这篇关于Laravel雄辩的ORM交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆