# config:cache makes env() return null

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

- URL: https://laravel-vuejs.space/php-artisan-config-cache-vue
- Author: Anass Ez-zouaine (https://laravel-vuejs.space/author/anass-ez-zouaine)
- Published: 2026-10-11
- Topics: Laravel, VueJs, Setup

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](https://laravel-vuejs.space/deploy-laravel-vue) 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.php`
```php
'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

**Q: Why does env() return null after config:cache?**

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

**Q: 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".
