@janewinkler This looks okay to me, but if you want to do this in fewer lines then do this
DB::transaction(function($conn){
DB::connection('db2')->transaction(function($conn){
// do your magic here
});
});
Summer Sale! All accounts are 50% off this week.
I'm currently working on an import tool that inserts data into two separate databases. The connections are set accordingly in the config folder. Everything I've come across regarding multiple database connection focuses on interacting with each separately. However, I need to insert into both. I'm wondering how to best implement transactions so that the commit and rollback works for both connections
It seems kind of janky to do this but I can't find anything else on this:
DB::beginTransaction(); //default connection is to db1`
DB::connection('db2')->beginTransaction();
try{
//logic
}catch(){
DB::rollBack();
DB::connection('db2')->rollBack();
}
DB::commit();
DB::connection('db2')->commit();
Please or to participate in this conversation.