Skip to content
Advertisement

Accessing the contents of .env via the env Facade

In my Laravel 7.x application, I added some basic configuration to my .env file, eg:

MY_SECRET_KEY=foo

In my controller, I am attempting to read in the value via the following:

Log::debug("ENV[MY_SECRET_KEY]: " . env('MY_SECRET_KEY'));

The result of the env shows up as an empty string in storage/logs/laravel.log:

[2020-09-05 18:38:58] local.DEBUG: ENV[MY_SECRET_KEY]:

I made sure to restart my docker container and verified that .env is indeed there and contains the populated env var. No typos.

Why else would it be coming up as empty?

Advertisement

Answer

Probably it’s cached. Try this

php artisan config:clear
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement