laravel transactions
snippet in php

laravel transactions

user7940

DB::beginTransaction();

try {
    DB::insert(...);
    DB::insert(...);
    DB::insert(...);

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}

TRANSACTON LARAVEL QUERY BUILDER

user1502

DB::beginTransaction();

try {
    DB::insert(...);    
    DB::commit();
} catch (\Throwable $e) {
    DB::rollback();
    throw $e;
}

laravel transaction query not working when multiple db connection

user3239

Start the transaction on the same connection your query will run on.