After I run php artisan config:cache the variables set in my .env-file are not being read properly in the application and if I do php artisan tinker I get:
>>> env('S3_KEY');
=> null
after doing php artisan config:clear everything is back to normal:
>>> env('S3_KEY');
=> "AERIAOEBNOIAERGOIEAJRI" // not my real key
How come config:cache has this effect?
Is it because I use e.g. S3_KEY in a config.php-file? Which is then set to null?
If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.
If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.
If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.
If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.
Can anyone explain this further? What's the reason behind this change?
And does it mean I cannot use env('SOME_VAR') at all anymore directly in my code except in the config files?
Will it work or will it break if I utilize the config cache?
I ended up adding each one into config/app.php (and referencing it as env('variable_name')) and just calling it properly with config('variable_name') from within the code
I think the main reason behind it is allowing users to set a default if the env file is missing the value requested