Bird
0
0

Which of the following is the correct way to access an environment variable named APP_NAME in Laravel code?

easy📝 Syntax Q12 of 15
Laravel - Configuration and Environment
Which of the following is the correct way to access an environment variable named APP_NAME in Laravel code?
Aconfig('APP_NAME')
Benv('APP_NAME')
C$_ENV['APP_NAME']
Dgetenv('APP_NAME')
Step-by-Step Solution
Solution:
  1. Step 1: Recall Laravel's helper for environment variables

    Laravel provides the env() helper function to access variables from the .env file.
  2. Step 2: Compare options

    config() accesses config files, not .env directly. $_ENV and getenv() are PHP ways but not recommended in Laravel.
  3. Final Answer:

    env('APP_NAME') -> Option B
  4. Quick Check:

    Use env() helper for .env variables = A [OK]
Quick Trick: Use env('VAR_NAME') to get .env values in Laravel [OK]
Common Mistakes:
  • Using config() instead of env()
  • Trying to access $_ENV directly
  • Confusing PHP native functions with Laravel helpers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes