laravel transaction commit code example
Example 1: laravel db transaction
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}
Example 2: transaction commit rollback in laravel
try {
$exception = DB::transaction(function() {
});
if(is_null($exception)) {
return true;
} else {
throw new Exception;
}
}
catch(Exception $e) {
return false;
}
Example 3: DB::transaction
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
} catch (\Exception $e) {
DB::rollback();
}