config 获取不了 admin.php 配置的值 原来是这个样子

从百度上找到这样的说法 https://blog.csdn.net/duanshuiliu2017/arti...

laravel 踩坑 env,config

正常情况:
env 方法 可以获取 .env 文件的值
config 可以获取 config 文件夹下 指定配置的值

非正常情况:
当我们执行了 php artisan config:cache 之后
在bootstrap/cache 文件夹下 会生成一个 config.php 文件
这个文件包含了 config 文件夹下的所有文件内容,并以文件名作为键值
同时把 .env 文件 根据特殊的解析方式,解析到 config.php

最终结果:
env 无法获取到 .env 文件的值
config 方法 只能获取到 bootstrap/cache/config.php 文件里面的值

解决方法
bootstrap/cache/config.php 删除
重新执行 php artisan config:cache

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

Laravel 官方文件 Configuration - Configuration Caching

其實官方文件就有特別標記說明這件事了

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.

此外, 應該不用手動刪除檔案

執行 config:clear就可以了

6年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!
未填写
文章
78
粉丝
8
喜欢
43
收藏
49
排名:82
访问:10.4 万
私信
所有博文
社区赞助商