Skip to content
Discussion options

You must be logged in to vote

Hey there.

You can achieve this using the config helper to create a new connection on the fly.
But first, you need to add an empty database name, like so:

    'sqlite' => [...],
    'mysql => [...],
+   'dynamic' => []

Then, using the config helper, you can assign the new connection to the empty one:

// The default connection
$default = config('database.connections.mysql');

// Merge the default connection values with the new connection values.
config([
  'database.connections.dynamic' => array_merge($default, [
      'username' => 'root',
      'database' => 'forge',
      #... other options
  ])
]);

// Now the framwork migrator will use the new database connection.
Artisan::call('migrate'

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thiagomeloo
Comment options

Answer selected by thiagomeloo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants