I'm using Lumen and Eloquent for the first time to build an API. I need to query the same table across several databases in one request. The algo I'm using is as follows:
foreach($db in $dbs) {
config(['database.connections.clientdb.database' => $db]);
$count = MyModel->all()->count()
$myArray[] = $count
}
Instead of getting an array of different values, the values are always the same; the value generated from the first database connection.
Since the first database is not the configured database, I know the config
command works (at least once). I verified that the database name does change on each iteration. I'm not (knowingly) using a cache. I used the $mymodel = new MyModel('$db') and executing the model's
setConnection()in the constructor then setting
$mymodel = null. The value of
$count` never changes.
I'm guessing the database connection isn't being released. How do I get Lumen/Laravel/Eloquent to tear down the database connection and connect to another one inside the same request?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire