I am creating a laravel project for which I need one laravel installation and use its instance in sub-domain with separate database. And th
Laravel supports multiple Database connections. Firstly, define the connections in config/database.php:
'default_connection',
'connections' => array(
// domain.com
'default_connection' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'primary_database',
'username' => 'username',
'password' => 'password'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
// sub.domain.com
'subdomain_connection' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'secondary_database',
'username' => 'username',
'password' => 'password'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
Now to specify which connection your models should use you can set the $connection property in your models:
You can set the value of $connection programatically.