Support the ongoing development of Laravel.io →
Configuration Security Database
Last updated 2 years ago.
0

you can use the connection method to change it, but user input? not sure

Schema::connection('foo')->create('users', function($table)
{
    $table->increments('id');
});
0

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', .

0

are you wanting to keep separate databases and credentials for each user ? multi tenancy ?

0

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.

Last updated 8 years ago.
0

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

0

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);
		}
	}

0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

December december Joined 22 Nov 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.