I have never used it, I just follow the upgrade guide and look through the code. However, I think it is just referring to hard coded configs instead of using ->config('CONFIG_ITEM') to access.
laravel shift, upgrade to 5.2 - use config() instead of env()
I'm upgrading my site to 5.2 using shift. One todo item says:
Laravel 5.2 added the env configuration option. Laravel strongly recommends you only use env() from configuration files and use config() within your app.
This is confusing. Is this suggesting to move all my config variables into conf/ files? The docs don't describe how config() method can access my variables in .env
Anybody else confused by this? I also have not found any documentation that supports the claim.
Are folks just using env() in application logic on laravel => 5.2?
I'll chime in here as well because I haven't seen anyone else mention it.
As @nztim mentioned, the config files are cached so anytime you call config(...) you're reading from a cached array. So there is a speed benefit.
But it's more than that. If you use env(...) outside of these cached config files, you will be reading directly from your .env file every time you call this function, which will almost certainly cause issues when you have a rapid succession of requests in your application, where the .env file can't be read (due to file locking issues, IIRC). I ran into this issue myself.
Read more here: https://laracasts.com/discuss/channels/general-discussion/laravel-intermittently-does-not-pull-from-environment-variables-correctly
Basically, the only place you ever use the getenv() or env() functions are in your config files (present in the /config/ directory). Then, you run the command php artisan config:cache which caches all those files. Then, you are only pulling your ENV variables once, upon deployment, and you won't have this issue anymore where there is a problem reading ENV variables (which is a complex issue involving more than just Laravel).
Please or to participate in this conversation.