Set custom database settings in Laravel

Asked

Viewed 194 times

0

My situation is as follows, I have several settings with the database set in the file databade.php, so far so good. But there are some connections that need data 'variables', such as the name of the database.

My question is whether it is possible to define these 'variables' data within the controller, as in the Codeigniter Framework.

  • 1

    http://stackoverflow.com/questions/17410049/laravel-4-connect-to-other-database

1 answer

1

You can do it like this:

$conn = array(
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'DATABASE',
    'username'  => 'USERNAME',
    'password'  => 'SOME_PASSWORD',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
);

Config::set('database.connections.DB_CONFIG_NAME', $conn);

In that link has other options.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.