← BACK
Laravel / Configuration

Retrieve and Override Configurations with the config() Helper

Punyapal Shah • • 1 min read
edit this tip →

Use config('app.name') to retrieve settings and config(['app.debug' => true]) to set runtime overrides.

The config() helper accesses application configuration options defined in config/*.php files. You can also pass key-value arrays to override configurations dynamically during testing or request execution.

// Retrieve config value with fallback default
$appName = config('app.name', 'Laravel');

// Override config value dynamically at runtime
config(['services.stripe.key' => 'pk_test_12345']);
  • Dot-notation syntax accesses nested configuration array keys
  • Passing key-value arrays overrides configurations dynamically for current request
  • Always use config() instead of env() outside config directory files

Related Tips

View all tips →
Laravel Configuration

Use config() Instead of env() in Application Code

Call env() only inside configuration files and use config() throughout your application code to prevent missing values when configuration is cached.

READ >
Laravel Configuration

Monthly Log Rotation with Laravel 13.23

Laravel 13.23 adds a built-in monthly logging driver that rotates log files once per month instead of daily.

READ >

// Got a tip in mind? Contributions are always welcome