# Laravel: .env changes ignored / env('X') returns null after php artisan config:cache

**Code:** `env() returns null (config cached)` · **Category:** Laravel · **Seen on:** Laravel, PHP

After `config:cache`, Laravel no longer reads `.env`, so `env()` calls outside config files return null and edits to `.env` have no effect.

## Meaning

When config is cached, `.env` isn't loaded; only values compiled into `config/*.php` exist. Use `config('app.x')` in app code and call `env()` only inside config files. After changing `.env` run `php artisan config:clear` (or `config:cache` again).

## Common causes

- `env()` used in controllers/models instead of `config()`
- `.env` edited but config cache not rebuilt
- Different `.env` on the server
- Cache stored from another environment
- `config/*.php` missing the key

## Quick fix

1. Read values via `config('services.key')` and define them in config files
2. `php artisan config:clear` after editing .env
3. Rebuild caches on deploy: `php artisan config:cache`

## Detailed fix by platform

### Laravel

1. `php artisan optimize:clear` clears config, route, view and event caches

## How to diagnose

1. **Cached** — bootstrap/cache/config.php exists?
2. **Usage** — env() outside config?
3. **Deploy** — Cache step?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/laravel/env-not-loaded-config-cache)
