you can use the connection method to change it, but user input? not sure
Schema::connection('foo')->create('users', function($table)
{
$table->increments('id');
});
astroanu said:
you can use the connection method to change it, but user input? not sure
Schema::connection('foo')->create('users', function($table) { $table->increments('id'); });
I mean with the option --database you can change the : 'database' => 'database', in the database config file. But I want to change dynamically the 'username' => 'root', .
are you wanting to keep separate databases and credentials for each user ? multi tenancy ?
astroanu said:
are you wanting to keep separate databases and credentials for each user ? multi tenancy ?
Yes only want for the migrate command other credentials.
You can set the database connection settings at run time. How i did this was create a provider that sets the database credentials at runtime based on the sub domain. You can use Config::set(key, val) or pass an array of keys values to the config() helper see https://laravel.com/docs/5.3/configuration#accessing-configuration-values
astroanu said:
You can set the database connection settings at run time. How i did this was create a provider that sets the database credentials at runtime based on the sub domain. You can use Config::set(key, val) or pass an array of keys values to the config() helper see https://laravel.com/docs/5.3/configuration#accessing-configuration-values
Do you mean here in the framework source I can't use Config::
/**
* Prepare the migration database for running.
*
* @return void
*/
protected function prepareDatabase()
{
$this->migrator->setConnection($this->input->getOption('database'));
if ( ! $this->migrator->repositoryExists())
{
$options = array('--database' => $this->input->getOption('database'));
$this->call('migrate:install', $options);
}
}
no, what i meant was no matter which user is logged in, assuming the db schema for the application would be same across all user databases: you will need to change the database connection for the user on the provider.
if you set the default db connection's credentials to the user's db credentials, the migration command should pick up that db as the default db
you could also try something like this: create a new command class extending Illuminate\Database\Console\Migrations\MigrateCommand then add your own options overriding the prepareDatabase method
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community