Bird
0
0

Given the config file config/database.php contains:

medium📝 component behavior Q4 of 15
Laravel - Configuration and Environment
Given the config file config/database.php contains:
return [
  'default' => 'mysql',
  'connections' => [
    'mysql' => [
      'host' => '127.0.0.1',
      'port' => 3306
    ]
  ]
];

What will config('database.connections.mysql.port') return?
A'127.0.0.1'
B3306
C'mysql'
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Trace the config array structure

    The 'database' config returns an array with 'connections' containing 'mysql' details including 'port' set to 3306.
  2. Step 2: Access nested keys with dot notation

    Using config('database.connections.mysql.port') accesses the 'port' value inside the 'mysql' connection array, which is 3306.
  3. Final Answer:

    3306 -> Option B
  4. Quick Check:

    Nested config access returns 3306 [OK]
Quick Trick: Dot notation drills down nested config arrays [OK]
Common Mistakes:
  • Returning the connection name instead of port
  • Confusing host and port values
  • Expecting string instead of integer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes