laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

Laravel Connection Purge and Reconnect not working

Open blpraveen opened this issue 4 years ago • 1 comments

  • 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

blpraveen avatar Jul 02 '21 08:07 blpraveen

 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');
    }

   

}

24bulut avatar Feb 27 '23 09:02 24bulut