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
Just stumbled across this question, and IMHO sometimes the simplest suggestion is the easiest.
I just place a simple switch at the head of the /config/database.php file:
switch($_SERVER['HTTP_HOST'])
{
case 'dev.yoursite.com':
$selectedDatabase = 'mysite_dev';
break;
case 'yoursite.com':
default:
$selectedDatabase = 'mysite_live';
break;
}
Then simply use the variable within the returned config variable.
return [
'connections' =>
['mysql' =>
['database' => $selectedDatabase,
'username' => 'user_name',
'password' => 'xxxxxxxxx',
],
]
];
I know its not the laravel way, but it'll get you out of a fix if you just want to open up a quick testing environment using the same PHP coding, but a test instance of your database.