Answers for "database transaction laravel"

PHP
6

laravel 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 May-19-2020
3

laravel 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
0

Db transaction laravel

DB::beginTransaction();

try {
    DB::insert(...);    
    DB::commit();
} catch (\Exception $e) {
    DB::rollback();
    throw $e;
} catch (\Throwable $e) {
    DB::rollback();
    throw $e;
}
Posted by: Guest on July-27-2021
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 "database transaction laravel"

Browse Popular Code Answers by Language