config 獲取不了 admin.php 配置的值 原來是這個樣子

chaofu發表於2018-07-25

從百度上找到這樣的說法 https://blog.csdn.net/duanshuiliu2017/article/details/79879463

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

相關文章