あなたが言うように、デフォルトではLaravelはホスト名を使用しますが、detectEnvironment
メソッドにクロージャーを渡して、より複雑なロジックを使用して環境を設定することもできます。
たとえば、次のようなものです。
$env = $app->detectEnvironment(function()
{
// if statements because staging and live used the same domain,
// and this app used wildcard subdomains. you could compress this
// to a switch if your logic is simpler.
if (isset($_SERVER['HTTP_HOST']))
{
if (ends_with($_SERVER['HTTP_HOST'], 'local.dev'))
{
return 'local';
}
if (ends_with($_SERVER['HTTP_HOST'], 'staging.server.com'))
{
return 'staging';
}
if (ends_with($_SERVER['HTTP_HOST'], 'server.com'))
{
return 'production';
}
// Make sure there is always an environment set.
throw new RuntimeException('Could not determine the execution environment.');
}
});
ただし、これは職人を扱っていません -HTTP_HOST
そこには設定されません。異なるサイトが異なるユーザーの下で実行されている場合は、たとえば、別の別の switch ステートメントを実行できます$_SERVER['USER']
。そうでない場合は、区別する方法としてインストールのパスを使用することもできます。