Answers for "laravel transaction db"

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
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
1

transaction commit rollback in laravel

// try...catch
try {
    // Transaction
    $exception = DB::transaction(function() {

        // Do your SQL here

    });

    if(is_null($exception)) {
        return true;
    } else {
        throw new Exception;
    }

}
catch(Exception $e) {
    return false;
}
Posted by: Guest on October-15-2020
0

transaction laravel

DB::beginTransaction();
try { /** Statement */   DB::commit(); } 
catch (\Exception $e) { /** Statement if failed */ DB::rollback(); }
Posted by: Guest on May-29-2021

Code answers related to "laravel transaction db"

Browse Popular Code Answers by Language