Answers for "how to use db transaction in laravel"

PHP
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

Code answers related to "how to use db transaction in laravel"

Browse Popular Code Answers by Language