config:cache makes env() return null

After config:cache, read config('app.name'). env() outside config files returns null.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/php-artisan-config-cache-vue.md
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 .env edits do nothing.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

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 .env edits do nothing.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
$name = config('app.name');

Put a new key in a config file first:

config/services.phpphp
'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".

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.