- Good discussion
- env() calls work as long as you don’t use php artisan config:cache. So it’s very dangerous because it will often work while development but will fail on production. See upgrade guide: https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0
- More information on caching for Laravel>5.6
- It is best practice, to not use env() throughout your application but create config files for these values. This will speed up your application in production. If you want to take advantage of config cache, you CAN NOT use env() anywhere but in your config files.
- If you stick with cache config in local, every time you update your config files or your .env file you will need to run
php artisan config:cache
- By running
php artisan config:clearor removing
/bootstrap/cache/config.phplaravel will no longer to attempt to read config from cache, and .env will work outside of config files.
- Once config cache is enabled,.env becomes useless, but it is used to build the cache.