Dynamically edit config/database.php file in Laravel

前端 未结 3 514
温柔的废话
温柔的废话 2021-02-06 14:29

First time when user runs my application i want to set database details as entered by the user in my application.

Please let me know how i can edit config/database.php f

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 15:01

    If you want to set the database connection dynamically for just one request you can also use the following option.

    Config::set('database.connections.local.host', '');
    Config::set('database.connections.local.database', '');
    Config::set('database.connections.local.username', '');
    Config::set('database.connections.local.password', '');
    

    Your DB config can looks like this in that case, or just provide default connection information and override it via the above commands.

    'connections' => array(
        'local' => array(
            'driver'    => 'mysql',
            'host'      => '',
            'database'  => '',
            'username'  => '',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_cli',
            'prefix'    => '',
         ),
    ),
    

提交回复
热议问题