我试图找出为什么我的env()助手总是返回null.这会引起麻烦,特别是在app.PHP文件中,默认情况下广泛使用的是env()助手.也许任何神秘的服务器设置?
我的环境文件:
APP_ENV=production
APP_KEY=base64:mymagickey=
APP_DEBUG=false
APP_LOG_LEVEL=info
APP_URL=http://www.example.com
etc...
编辑 – 我试过以下:
PHP artisan cache:clear
PHP artisan view:clear
PHP artisan config:cache
当然,我正在使用这样的env帮助:env(‘APP_ENV’)
但仍然没有成功.奇怪的是,$_ENV PHP变量包含来自.env文件的每个变量. 解决方法: 缓存配置后,env(…)函数将无法工作. (从laravel 5.2开始直到5.7)
Laravel documentation说
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.
我从同一个documentation引用它
但是为了快速解决这个问题:
PHP artisan config:clear
现在应该清楚为什么,当你尝试config:cache时,它没有帮助,即使它在缓存之前清除了配置. (编辑:北几岛)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|