Reputation: 172
Laravel4 how to switch database name at runtime.
I know there is a way to change the database config.
Schema::connection('foo')->create('users', function($table)
{
$table->increments('id');
});
But I need to create many databases. Can not write them all in a file database.php.
thank for advance
Upvotes: 0
Views: 470
Reputation: 172
Finally i found a solution.
Config::set('database.connections.mysqlCustom.database','databaseName');
Schema::connection('mysqlCustom')->create('product', function(Blueprint $table ) {
$table->increments('id');
$table->string('title');
$table->timestamps();
});
Hopefully it will help people who have problem like me.
Upvotes: 1