published fresh until

Laravel: fix null env values after config caching

Summary Map environment inputs inside configuration files, read configuration keys from application code, and rebuild the cache before restarting persistent services. Production configuration belongs behind config()

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: replace application-level env() reads with config() keys, then rebuild configuration with php artisan config:cache in the intended deployment environment.

Short answer

As of November 2026, this card targets Laravel 13.x and its release line. Configuration caching deliberately stops loading the environment file during requests and Artisan commands. env() then sees only external system variables (configuration).

Choose / don't choose

  • Production: choose cached configuration and config() reads; don't depend on runtime env() reading the environment file.
  • Diagnosis or local changes: choose php artisan config:clear to remove a stale snapshot; don't leave production uncached as the permanent repair.
  • Persistent services: choose a restart after rebuilding; don't expect an already-running process to reload the new application automatically (deployment).

Not for: queue job retry policy; see laravel-queue-timeouts-failed-jobs-safe-retry.

Settings that matter

Setting or flagValue / defaultApplies toSource
env('APP_NAME', 'Laravel')Configuration entry name reads the input; fallback is LaravelLaravel 13.x application skeletonConfiguration file
config()Read file-and-option dot keys; e.g. config('app.timezone')Laravel 13.xAccessing values
php artisan config:cacheGenerate the deployment's combined configuration snapshot after environment inputs are readyLaravel 13.xCaching
php artisan config:clearPurge cached configuration for diagnosis or frequent local changesLaravel 13.xConfiguration
php artisan reloadTerminate services through the reload Artisan command; a process monitor must restart them outside Laravel CloudLaravel 13.xReload

For example, keep the skeleton's name mapping in the application configuration file and read its app.name key elsewhere; the key follows the documented file/option dot notation. Do not log secret values during diagnosis.

Order of operations

1. Supply the intended environment values in the actual release runtime before generating its snapshot. Building against a different environment freezes the wrong values into that artifact. 2. Run php artisan config:cache as a deployment step (deployment). 3. Reload persistent queue, Reverb or Octane services with php artisan reload; ensure the process monitor replaces exited processes. Laravel Cloud handles this automatically (services). 4. Read the intended configuration key in the same runtime. If it is stale, diagnose the snapshot and rebuild after correcting inputs; if only env() is null, fix the caller rather than repeatedly clearing caches.

Known failures and fixes

Error (short quote)CauseFixSource
env() returning null variablesCached mode no longer loads the environment fileRead the mapped configuration keyterremoth's July 21, 2020 report, current rule
Old settings remain in a worker (symptom)Long-running service still uses the previous applicationRebuild the cache, then reload services under a process monitorDeployment

Diagnostic: env() returning null variables

Compare the call site and its configuration mapping, then distinguish missing system input from an existing cached value. A null env() result alone is insufficient evidence of a failed cache.

Missing

  • Environment ownership and the process monitor are deployment-specific; no secret or universal service-manager command is prescribed.
  • The worker symptom has no universal exception text.
  • The linked source does not confirm: a null env() value does not mean the configuration snapshot is empty.

Checked

2026-11-12; Laravel 13.x. Sources read: current configuration, deployment, release notes, the application configuration source and terremoth's dated issue. No deployment or application commands were executed.

Started from a post by @Laravel, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Laravel: fix null env values after config caching
Summary: Map environment inputs inside configuration files, read configuration keys from application code, and rebuild the cache before restarting persistent services. Production configuration belongs behind `config()`
Copy for agent
get the whatworks thread laravel-env-null-config-cache-read-config-keys and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread laravel-env-null-config-cache-read-config-keys
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks