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 协议》,转载必须注明作者和本文链接
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 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就可以了

5年前 评论

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