Is laravel's .env file only valid when called within the config folder?
给我你的怀抱
给我你的怀抱 2017-06-13 09:24:33
0
2
871

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?

给我你的怀抱
给我你的怀抱

reply all(2)
黄舟

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)

Caching And Env

If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

If you are calling env from within your application, it is strongly recommended you add proper configuration values ​​to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

Excerpted from https://laravel.com/docs/5.2/...

Peter_Zhu

Laravel has an auxiliary function env() Yeah = =

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!