Forcing Eloquent models to re resolve database connection

后端 未结 2 1298
你的背包
你的背包 2020-12-21 21:20

Is there any way to force Eloquent models to re resolve the connection they were instantiated with?

Right now I have a method that changes the database connection in

2条回答
  •  没有蜡笔的小新
    2020-12-21 21:50

    In my case, I did not have a database config for each of my databases, since they are created dynamically. I used the following approach, just changing the table name to include the database name as well (This works for MySQL):

    foreach ($array as $key => $value) {
       $productRepo = new ProductRepository();  
       $productRepo->setTable($key . '_' . $database);  
       $products = $productRepo->all();
    }
    

提交回复
热议问题