5. You want to create a new config file config/payment.php with a key gateway that uses an environment variable PAYMENT_GATEWAY defaulting to 'stripe'. How should you write the config file to access this value correctly in Laravel?
hard
A. env('PAYMENT_GATEWAY', 'stripe')];
B. config('PAYMENT_GATEWAY', 'stripe')];
C. 'PAYMENT_GATEWAY' ?? 'stripe'];
D. getenv('PAYMENT_GATEWAY', 'stripe')];
Solution
Step 1: Use env() to read environment variables in config
Laravel config files use env('VAR_NAME', 'default') to get env vars with defaults.
Step 2: Write correct PHP array return
Return an array with key 'gateway' set to env('PAYMENT_GATEWAY', 'stripe').
Final Answer:
<?php
return ['gateway' => env('PAYMENT_GATEWAY', 'stripe')]; -> Option A
Quick Check:
Use env() in config files for env vars [OK]
Hint: Use env() with default inside config files [OK]
Common Mistakes:
Using config() inside config files instead of env()
Using getenv() without fallback default
Using PHP null coalescing incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.