begin transaction in laravel code example
Example 1: laravel transactions
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
// all good
} catch (\Exception $e) {
DB::rollback();
// something went wrong
}
Example 2: laravel transaction query not working when multiple db connection
Start the transaction on the same connection your query will run on.