I have searched a lot about it and tried every possible solution I could find or think of.
So I am changing database configuration to a new database as follows:
DB::disconnect('mysql');
config(['database.connections.mysql.database' => $new_db_name]);
If i try to get the database name like:
dd(config('database.connections.mysql.database'));
I get the right database name which I just set. But when i try to run migration on it:
\Artisan::call('migrate', ['--database' => $new_db_name ]);
I get the error : Database [$new_db_name] not configured
Any help is appreciated.
The problem is that
--database
parameter is quite confusing. It shouldn't hold database name but database connection name, so in your case:should do the trick.