Environment detection by URL was removed in 4.1 (see upgrade guide "Environment Detection Updates").
Hi kokokurak,
If you want detect by domain name you can do it like this:
$env = $app->detectEnvironment(function()
{
$env = '';
switch($_SERVER['HTTP_HOST']){
case 'test.localhost.dev':
$env = 'dev';
break;
}
return $env ?: 'production';
});
But it's not the goo way to detect the environment because:
. The environment is not detected properly in CLI . Domain spoofing
To configure properly one application I use this way:
$env = $app->detectEnvironment(function()
{
$env = getenv('LARAVEL_ENV');
if(empty($env)){
if(file_exists(__DIR__.'/../.env')){
$env = trim(file_get_contents(__DIR__.'/../.env'),"\n");
}
}
return $env ?: 'local';
});
I use getenv to get the environment name put in the vhost configuration LARAVEL_ENV
.
SetEnv LARAVEL_ENV staging
If you can put environment variable on your vhost you can put a .env
file at the root of your application en put the environment name.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community