Laravel 4: how can I get the environment value?
我知道我可以使用全局
您很幸运-Beta 4中刚刚添加了该功能-详情请参见此处
Added App::environment method.
编辑:这些是从Laravel 4.1开始获取环境变量的多种方法
1 2 3 4 | App::environment() app()->environment() app()->env $GLOBALS['env'] // not recommended - but it is possible |
您还可以专门检查当前环境是否设置为"本地"
1 2 | App::isLocal() app()->isLocal() |
您还可以专门检查当前环境是否设置为"测试"
1 2 | App::runningUnitTests() app()->runningUnitTests() |
您也可以使用
在Laravel 4和5中,Laravel官方文档建议使用:
1 | $environment = App::environment(); |
You may also pass arguments to the environment method to check if the
environment matches a given value:
1 2 3 4 5 6 7 8 9 | if (App::environment('local')) { // The environment is local } if (App::environment('local', 'staging')) { // The environment is either local OR staging... } |