DB transaction rollback runs there is exception

Posted 5 months ago by michaelnguyen547

finally always run no matter there are exceptions or not.

I am looking for a way to run DB::rollback only if there are exceptions

DB::transaction();

try {
    // do some works with db
    DB::commit();
} catch (PaymentException $e) {
    DB::rollback();
} catch (RareException $e) {
    DB::rollback()
} catch (Throwable $e) {
   DB::rollback();
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.