Laravel从错误的目录中提取数据库设置


Laravel pulling database settings from wrong dir

我创建了app/config/mysite.dev,并将app.phpdatabase.php添加到此目录中。然后,我将bootstrap/start.php中本地、暂存和生产的值更改为引用mysite.dev。然而,它不是检查app/config/mysite.dev/database.php的设置,而是读取app/config/database.php

我觉得我错过了关键的一步。

有什么想法吗?

这是我的bootstrap/start.php文件:

<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new Illuminate'Foundation'Application;
/*
|--------------------------------------------------------------------------
| Detect The Application Environment
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name or HTTP host that matches a
| given environment, then we will automatically detect it for you.
|
*/
$env = $app->detectEnvironment(array(
    'local' => array('mysite.dev'), // Change this to your local machine hostname.
    'staging' => array('mysite.dev'),
    'production' => array('mysite.dev'),
));
/*
|--------------------------------------------------------------------------
| Bind Paths
|--------------------------------------------------------------------------
|
| Here we are binding the paths configured in paths.php to the app. You
| should not be changing these here. If you need to change these you
| may do so within the paths.php file and they will be bound here.
|
*/
$app->bindInstallPaths(require __DIR__.'/paths.php');
/*
|--------------------------------------------------------------------------
| Load The Application
|--------------------------------------------------------------------------
|
| Here we will load the Illuminate application. We'll keep this is in a
| separate location so we can isolate the creation of an application
| from the actual running of the application with a given request.
|
*/
$framework = $app['path.base'].'/vendor/laravel/framework/src';
require $framework.'/Illuminate/Foundation/start.php';
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;

如果您确定您的主机名是"mysite.dev",并且您已将数据库配置放在app/config/mysite.dev/database.php中,那么您需要以下$app->detectEnvironment

$env = $app->detectEnvironment(array(
    'mysite.dev' => array('mysite.dev')
));

我建议将app/config/mysite.dev/database.php重命名为app/config/dev/database.php,然后使用以下内容:

$env = $app->detectEnvironment(array(
    'dev' => array('mysite.dev')
));

正如评论中所说:数组中的键与文件夹名称相对应,而值是包含计算机主机名的数组