本来在Laravel里面根据env文件配置不同来实现不同功能是一件很美好的事情,但是往往可能遇到坑。
在代码里面直接使用env函数来获取配置,很有可能获取不到。解决办法也许可以先在config文件里面读取env文件,再在代码里使用config值。

参考一下内容:

A few things to bear in mind:

Laravel recommends only to use env() within the config files. Use the config() helper in your code instead of env(). For example you can call config('APP_ENV') in your code.

When you use php artisan config:cache all the configuration strings are cached by the framework and any changes you make to your .env file will not be active until you run the php artisan config:cache command again.



Laravel

登陆发表评论