People searching “Laravel env returns null” call env('APP_NAME') in a controller after production cached the config. php artisan config:cache bakes config/*.php into one file and stops reading .env on each request. env() outside those config files is null. The deploy guide is where the cache is built.
TL;DR
- After config:cache, read config(‘app.name’).
- env() outside config files returns null.
- Do not call
env()in a Vue prop “just this once”. - Do not cache config in local development and then wonder why
.envedits do nothing.
The fix#
$name = config('app.name');Put a new key in a config file first:
'maps_key' => env('MAPS_KEY'),Then read config('services.maps_key'). Change .env, then rebuild the cache. Editing .env alone does nothing while the cache exists.
What to avoid#
Gotcha
Do not call env() in a Vue prop “just this once”. Do not cache config in local development and then wonder why .env edits do nothing. Local should stay uncached. php artisan config:clear drops the cache.
FAQ#
Why does env() return null after config:cache?
After config:cache, read config('app.name'). env() outside config files returns null.
What goes wrong with Laravel env returns null?
Many developers call env('APP_NAME') in a controller after production cached the config. Do not call env() in a Vue prop "just this once".



