config/app.php contains 'name' => 'MyApp', what will config('app.name') return?<?php // config/app.php return [ 'name' => 'MyApp', ]; // In a controller or route $value = config('app.name'); echo $value;
The config() helper uses dot notation to access nested keys in config files. Since app.php returns an array with key 'name', config('app.name') returns the value 'MyApp'.
app.timezone, but provide a default of 'UTC' if it is not set. Which code does this correctly?The config() helper accepts a second argument as the default value if the key is missing. So config('app.timezone', 'UTC') returns the config value or 'UTC' if not set.
config('database.connections.mysql.host');
The database.php config file returns an array but the connections key is missing. What error will this cause?<?php // database.php return [ // 'connections' key is missing ]; // Accessing $host = config('database.connections.mysql.host');
Laravel's config() helper returns null if the key path does not exist. It does not throw an error for missing nested keys.
To set config values at runtime, you pass an associative array to the config() helper. For example, config(['app.debug' => true]) sets the value.
config(['app.locale' => 'fr']);
echo config('app.locale');
What will be printed?config(['app.locale' => 'fr']); echo config('app.locale');
After setting app.locale to 'fr' at runtime, calling config('app.locale') returns 'fr'.
