我想要自定义环境检测。我知道现有的 Laravel 环境检测是如何工作的,但我想要一种更动态的方式。我想在我的 Ubuntu 环境中导出一个变量,建议它是“开发”或“生产”,而不是使用主机名和 IP地址。
任何帮助都会很棒,谢谢。
最佳答案
我在项目中所做的是创建一个文件“app/bootstrap/environment.php”
环境.php
<?php
//Get the environment
$environment = getenv('ENV');
//Check if the environment has been set
if(is_string($environment) && ($environment != '')){
//Return the environment
return $environment;
}else{
//On default return production environment
return 'production';
}
然后在“app/bootstrap/start.php”中
start.php
$env = $app->detectEnvironment(function()
{
//Return the environment we're currently using
return require __DIR__.'/environment.php';
});
非常适合我。
关于php - Laravel 环境检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25325305/