Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

laravel config set not working in database seeder? seeds existing connection?

$
0
0

I have an issue where I am struggling to set the database connection for a database seeder. I am trying to set the config for the updated DB details, however when I call the migrate artisan command, it gets the existing connection details from the config/database.php and then seeds the wrong database.

Why is Config::set not overwriting the connection details?

My seeder:

public function run(){    $databases = SchoolDatabase::all();    foreach ($databases as $db) {        Config::set('database.connections.school', ['driver'   => 'mysql','host'     => $db->host,'port'     => $db->port,'database' => $db->database_name,'username' => $db->database_username,'password' => $db->database_password,        ]);        Artisan::call('db:seed',            ['--database' => 'school','--class' => 'SchoolStudentSeeder'            ]        );    }}

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>