DB::transactions do not work when using DB::connection()
Create a non-default config for a mysql database.
Attempt to run the following code:
````
DB::beginTransaction();
try {
DB::connection('newdb')->table('users')->where('id', 2)->update(['status' => 'VALIDATED']);
throw new \Exception('Some new exception');
DB::commit();
} catch ( Exception $ex ){
DB::rollBack();
}
````
The DB transaction is immediately committed at the update statement and can not be rolled back.
Start the transaction on the same connection your query will run on.
Duh... Thank you!
@themsaid thank you very much. I think this specific point with multi database connections could be added in documentation.
Can I help for that @taylorotwell ?
Most helpful comment
Start the transaction on the same connection your query will run on.