0

Suppose I have codes as below

DB::beginTransaction();
try {
    ...
    DB::commit();
} catch (\Exception $e) {
    DB::rollback();
    return back()->with('err', translate('something_went_wrong', 'Something Went Wrong. Please contact customer support.'));
}

Do I still need to call DB::rollback()? I saw similar codes on stackoverflow but I am wondering the necessity of having DB::rollback() because the transaction is never committed if something went wrong in between.

Edward Chew
  • 492
  • 3
  • 12
  • 1
    Yes, you can. You are doing it right. – Digvijay May 28 '20 at 04:18
  • @gre_gor, thank you, it does answer it to a certain extend. If we begin a DB transaction within a request lifecycle. will it be closed automatically when the request lifecycle ends? (Without committing the transaction). Or will the it be committed together with next successful transaction in another request? – Edward Chew May 28 '20 at 05:40

0 Answers0