Answers for "begin transaction laravel"

PHP
6

laravel transactions

DB::beginTransaction();

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

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}
Posted by: Guest on May-19-2020
3

DB::transaction

use Illuminate\Support\Facades\DB;

DB::transaction(function () {
    DB::update('update users set votes = 1');

    DB::delete('delete from posts');
});
Posted by: Guest on December-09-2020
1

DB::transaction

DB::beginTransaction();

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

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}
Posted by: Guest on October-20-2020
4

TRANSACTON LARAVEL QUERY BUILDER

DB::beginTransaction();

try {
    DB::insert(...);    
    DB::commit();
} catch (\Throwable $e) {
    DB::rollback();
    throw $e;
}
Posted by: Guest on September-22-2020

Browse Popular Code Answers by Language