The author writes a Artisan
command and calls the getenv
method in the command
file under App\Console
to obtain .env
configuration, the result returns null;
But by getting the configuration of .env
in config/services.php
, and then in the command
file under App\Console
By calling the config
method, you can get the desired environment variable value. Why is this?
The official suggestion is to call env in config and call config elsewhere.
This is actually a big pitfall. When I first wrote Laravel, I found that the env could not be read in the controller. (It’s not that it can’t be read 100%, it’s just that it can’t be read after executing php artisan config:cache)
Excerpted from https://laravel.com/docs/5.2/...
Laravel has an auxiliary function
env()
Yeah = =