I have this console command code:
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;
}
}
In the line of dd()
it should print the domain what I gave as parameter (coming from .env.example.com
, but still print the data from .env
file.
Otherwise this function is working well in AppServiceProvider
with this code:
$host = request()->getHost();
// read domain based .env file, like: .env.example.com
$dotenv = \Dotenv\Dotenv::createImmutable(base_path(), '.env.' . $host);
$dotenv->load();
Any idea how can I make it work in console command?