Here i’m going to define how to use laravel database transactions is in your project between the query.
If you are using transactions query so that you can of this, that is the best way for maintaining SQL transaction.
And If you are using set of transactions with your database in loop and its taking long time in processing so here you can implement transactions then your processing surely will fast.
First of all, you need to make sure you have imported DB library above other wise you can use directly by using farwrd slash.
DB::beginTransaction();
DB::rollback();
DB::commit();
Note: Any exception thrown within the transaction closure will cause the transaction to be rolled back automatically.
For example-
try{
DB::beginTransaction();
//here your logics and code
DB::commit();
return [“status”=>”success”,”msg”=>”success”];
}catch(Exception $e){
DB::rollback();
return [“status”=>”failed”,”msg”=>$e->getMessage()];
}
Hi!
I really appreciate your efforts in writing such a detailed post. I hope you will share more info about this. Thank you keep posting!