如何在 Laravel 4 中设置本地环境
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24108346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set local environment in Laravel 4
提问by God?
I just want to set the local environment into Laravel 4.
我只是想将本地环境设置为 Laravel 4。
In bootstrap/start.php
I have:
在bootstrap/start.php
我有:
$env = $app->detectEnvironment(array(
'local' => ['laravel.dev', ''],
));
I tried change local to development index in array, but nothing works. I tried some tips of this page: http://laravel.com/docs/configuration... nothing.
我尝试将本地更改为数组中的开发索引,但没有任何效果。我尝试了这个页面的一些提示:http: //laravel.com/docs/configuration...没有。
I'm using artisan in console, that always say me:
我在控制台中使用工匠,总是说我:
**************************************
* Application In Production! *
**************************************
Do you really wish to run this command?
What I might do to teach Lara that I'm on local environment?
我该怎么做才能让 Lara 知道我在当地环境中?
回答by The Alpha
You may try this (In bootstrap/start.php
file):
你可以试试这个(在bootstrap/start.php
文件中):
$env = $app->detectEnvironment(array(
'local' => ['*.dev', gethostname()],
'production' => ['*.com', '*.net', '*.org']
));
Also this is possible:
这也是可能的:
$env = $app->detectEnvironment(function() {
return gethostname() == 'your local machine name' ? 'local' : 'production';
});
回答by Sebastian Sulinski
Following on from @The Alpha's great answer - here's a slight modification using array to check for local machines (when you work from more than one location):
继@The Alpha 的精彩回答之后 - 这是使用数组检查本地机器的轻微修改(当您在多个位置工作时):
$env = $app->detectEnvironment(function() {
return in_array(
gethostname(),
[
'first local machine name',
'second local machine name'
]
) ?
'local' :
'production';
});
回答by akash varlani
$env = $app->detectEnvironment(function() {
$substr = substr(gethostname(), "-4");
return ($substr == ".com" || $substr == ".net" || $substr == ".org") ? 'production' : 'local';
});