For most application code, use the helpers.
$appName = env('APP_NAME', 'Quantum');
$dbHost = env('DB_HOST', '127.0.0.1');This works only after the shared Environment instance has been loaded during bootstrap.
$environment = environment();
if ($environment->isProduction()) {
// production-only behavior
}You can also read the raw environment name with getAppEnv().
$environment = environment();
$environment->setMutable(true);
$environment->updateRow('APP_NAME', 'Quantum 3');Use this carefully:
- mutability is off by default
- the target file must already have been selected and loaded
- updates modify the real
.envfile underApp::getBaseDir()
$server = server();
$method = $server->method();
$uri = $server->uri();
$contentType = $server->contentType(true);
$ip = get_user_ip();$headers = server()->getAllHeaders();
$requestId = $headers['x-request-id'] ?? null;Remember that the keys are normalized to lowercase hyphenated names.
- treat
Environmentas bootstrap-loaded configuration state, not as a reloadable store - use
env()for reads and keep directEnvironmentmutation limited to tooling or controlled setup flows - use
server()when you want one shared request metadata object instead of touching$_SERVERdirectly - be careful with
Server::ip()behind proxies because it prefers client-supplied forwarding headers