laravel use db transaction code example
Example 1: laravel db transaction
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
// all good
} catch (\Exception $e) {
DB::rollback();
// something went wrong
}
Example 2: transaction laravel
DB::beginTransaction();
try { /** Statement */ DB::commit(); }
catch (\Exception $e) { /** Statement if failed */ DB::rollback(); }