如何在Laravel 4中设置本地环境

10

我只想将本地环境设置为Laravel 4。

bootstrap/start.php文件中,我有以下内容:

$env = $app->detectEnvironment(array(
    'local' => ['laravel.dev', ''],
));

我试图在数组中将本地索引更改为开发索引,但是什么都没用。

我尝试了这个页面上的一些技巧:http://laravel.com/docs/configuration... 没有用。

我在控制台中使用artisan命令,它总是告诉我:

**************************************
*     Application In Production!     *
**************************************

Do you really wish to run this command?

我应该怎样做才能教Lara知道我正在使用本地环境?

3个回答

43

您可以尝试这样做(在bootstrap/start.php文件中):

$env = $app->detectEnvironment(array(
    'local' => ['*.dev', gethostname()],
    'production' => ['*.com', '*.net', '*.org']
));

还有这种可能:

$env = $app->detectEnvironment(function() {

    return gethostname() == 'your local machine name' ? 'local' : 'production';
});

欢迎您,@kinho,希望您知道如何接受答案 :-) - The Alpha
1
本地环境可以运行,但还没有尝试过生产环境。顺便说一句,谢谢! - Adrian Enriquez

3

在@The Alpha的出色回答之后,这里使用数组进行了轻微修改以检查本地机器(当您从多个位置工作时):

$env = $app->detectEnvironment(function() {

    return in_array(
            gethostname(), 
            [
                'first local machine name', 
                'second local machine name'
            ]
        ) ? 
        'local' : 
        'production';

});

0
$env = $app->detectEnvironment(function() {

    $substr = substr(gethostname(), "-4");
    return ($substr == ".com" || $substr == ".net" || $substr == ".org") ? 'production' : 'local';

});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接