那是因為 config:cache會把env cache 到 config ,其實沒必要再透過env取得環境
此時只要使用config function即可取得env設定的值
比如果要取得APP_ENV ,如果沒有cache,可以藉由getenv('APP_KEY') 取得
但cache則用 comfig('app.env') 取得(app.env 代表在config資料夾中的app.php 中的 env)
其實官方在升級說明也有提到此問題,也解釋說cache後用config即可,也比較符合cache的目的
https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0
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.
沒有留言:
張貼留言