Bird
0
0

Given the config file config/mail.php contains:

medium📝 component behavior Q13 of 15
Laravel - Configuration and Environment
Given the config file config/mail.php contains:
return [
  'driver' => env('MAIL_DRIVER', 'smtp'),
  'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
];

And the environment variable MAIL_DRIVER is set to sendmail, what will config('mail.driver') return?
A"smtp"
B"sendmail"
Cnull
D"smtp.mailtrap.io"
Step-by-Step Solution
Solution:
  1. Step 1: Understand env() usage in config

    The config uses env('MAIL_DRIVER', 'smtp'), which returns the environment variable if set, else 'smtp'.
  2. Step 2: Check environment variable value

    Since MAIL_DRIVER is set to 'sendmail', env('MAIL_DRIVER', 'smtp') returns 'sendmail'.
  3. Final Answer:

    "sendmail" -> Option B
  4. Quick Check:

    env() returns env var if set, else default [OK]
Quick Trick: env() returns env var first, default second [OK]
Common Mistakes:
  • Assuming default value always returns
  • Confusing config key with env variable name
  • Ignoring environment variable settings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes