transakce Laravel db
DB::beginTransaction();
try {
DB::insert(...);
DB::insert(...);
DB::insert(...);
DB::commit();
// all good
} catch (\Exception $e) {
DB::rollback();
// something went wrong
}
TRANSACTON LARAVEL QUERY BUILDER
DB::beginTransaction();
try {
DB::insert(...);
DB::commit();
} catch (\Throwable $e) {
DB::rollback();
throw $e;
}
DB:: transakce
use Illuminate\Support\Facades\DB;
DB::transaction(function () {
DB::update('update users set votes = 1');
DB::delete('delete from posts');
});
vrácení závazku transakce v Laravelu
// 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;
}
transakce laravel
DB::beginTransaction();
try { /** Statement */ DB::commit(); }
catch (\Exception $e) { /** Statement if failed */ DB::rollback(); }
Laravel transakce dotaz nefunguje, když více db připojení
Start the transaction on the same connection your query will run on.