LoginSignup
10
19

More than 5 years have passed since last update.

LaravelでのDBトランザクション

Posted at

こんな感じ。

DB::beginTransaction();
    try {
      $blog = Blog::find($id);
      $blog->comments()->detach();
      $blog->delete();
      DB::commit();
      $success = true;
    } catch (\Exception $e) {
      $success = false;
      DB::rollback();
    }

【参考】
http://programmer-jobs.blogspot.jp/2017/02/laravel-5-4-database-transactions.html

10
19
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
19