What is the config() helper in Laravel?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Laravel topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

The config() helper accesses configuration values from the files in the config/ directory using dot notation. config("app.name") reads the name key from config/app.php. config("database.connections.mysql.host") reads a nested value. Provide a default: config("app.locale", "en"). Set at runtime: config(["app.locale" => "fr"]) (only for the current request). Configuration files read environment variables via env() — but in application code, always call config(), not env() directly, because configuration values are cached with php artisan config:cache, and env() returns null in a cached environment. Clear config cache: php artisan config:clear.

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Laravel project.