1use Illuminate\Support\Facades\DB;
2
3DB::transaction(function () {
4 DB::update('update users set votes = 1');
5
6 DB::delete('delete from posts');
7});
1DB::beginTransaction();
2
3try {
4 DB::insert(...);
5 DB::insert(...);
6 DB::insert(...);
7
8 DB::commit();
9 // all good
10} catch (\Exception $e) {
11 DB::rollback();
12 // something went wrong
13}
14