1 回答
TA贡献1898条经验 获得超8个赞
用于:useEnvironmentPath()_bootstrap/app.php
$app->useEnvironmentPath($env_path);
或作为解决方案:
$app->useEnvironmentPath(
dirname(__DIR__, 2)
);
__DIR__返回当前文件的完整路径(因为您在bootstrap/app.php)
dirname(__DIR__, 2),从您的文件位置返回 2 个步骤(在您的情况下,它返回您的Project目录路径)
现在 Laravel 应该读取你的新.env文件。
- 更新 -
对于 HTTP 应用程序,更新app/Http/Kernel.php:
use Illuminate\Routing\Router;
use Illuminate\Contracts\Foundation\Application;
//////
/**
* Create a new HTTP kernel instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function __construct(Application $app, Router $router)
{
$app->useEnvironmentPath(dirname(__DIR__, 3));
parent::__construct($app, $router);
}
对于控制台应用程序,编辑app/Console/Kernel.php:
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Foundation\Application;
/////
/**
* Create a new console kernel instance.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function __construct(Application $app, Dispatcher $events)
{
$app->useEnvironmentPath(dirname(__DIR__, 3));
parent::__construct($app, $events);
}
并且app/Providers/AppServiceProvider.php:
public function boot() {
app()->useEnvironmentPath(dirname(__DIR__, 3));
}
- 1 回答
- 0 关注
- 189 浏览
添加回答
举报