laravel-mongodb
laravel-mongodb copied to clipboard
Laravel Connection Purge and Reconnect not working
- Laravel-mongodb Version: Latest
- PHP Version: 7.4
- Database Driver & Version: MongodB
Description:
I tried to reconnect to different db connection and run migration it is still running migration with default connection
Steps to reproduce
DB::purge('tenant');
DB::reconnect('tenant');
Schema::connection('tenant')->getConnection()->reconnect();
Expected behaviour
It should connect to new connection and Run the migration files
Actual behaviour
It is running migration in the default connection
public static function connectMongo($userId = null)
{
//Modellerin içerisinde zaten connection tanımlı buradaki temel olay dbname değişikliği
if (\Illuminate\Support\Facades\Config::get('database.connections.mongodb.database') != 'user_id_' . $userId){
DB::purge('mongodb');
\Illuminate\Support\Facades\Config::set('database.connections.mongodb.database', 'user_id_' . $userId);
DB::reconnect('mongodb');
}
}