【发布时间】:2021-05-09 14:31:08
【问题描述】:
我有这个控制台命令代码:
class MyCommand extends Command
{
protected $signature = 'custom:mycommand {domain}';
// ...
public function handle()
{
$domain = $this->argument('domain');
// read domain based .env file, like: .env.example.com
$dotenv = \Dotenv\Dotenv::createImmutable(base_path(), '.env.' . $domain);
$dotenv->load();
dd(env('APP_URL'));
// ...
return 0;
}
}
在dd() 的行中,它应该打印我作为参数提供的域(来自.env.example.com,但仍打印来自.env 文件的数据。
否则此函数在AppServiceProvider 中使用此代码运行良好:
$host = request()->getHost();
// read domain based .env file, like: .env.example.com
$dotenv = \Dotenv\Dotenv::createImmutable(base_path(), '.env.' . $host);
$dotenv->load();
知道如何让它在控制台命令中工作吗?
【问题讨论】:
-
你试过
$app->loadEnvironmentFrom('.env.example.com');$app你是 Laravel 应用吗。 -
是的,也没有用
标签: laravel laravel-environment laravel-console