0
0
Laravelframework~10 mins

.env file and environment variables in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get the value of an environment variable in Laravel.

Laravel
$value = env([1]);
Drag options to blanks, or click blank then click option'
A'APP_NAME'
BAPP_NAME
Capp_name
D"APP_NAME"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the environment variable name.
Using a variable name without quotes.
2fill in blank
medium

Complete the code to set a default value when an environment variable is missing.

Laravel
$value = env('APP_ENV', [1]);
Drag options to blanks, or click blank then click option'
Anull
Bproduction
C'APP_ENV'
D"production"
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the default string value.
Using the environment variable name as default.
3fill in blank
hard

Fix the error in the code to correctly access the database host from the environment.

Laravel
"DB_HOST=[1]"
Drag options to blanks, or click blank then click option'
A'DB_HOST'
BDB_HOST
Cenv('DB_HOST')
Dgetenv('DB_HOST')
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without the env function.
Using PHP's getenv instead of Laravel's env.
4fill in blank
hard

Fill both blanks to correctly define and access a custom environment variable.

Laravel
In .env file: CUSTOM_VAR=[1]
In code: $value = env([2]);
Drag options to blanks, or click blank then click option'
A"custom_value"
B"CUSTOM_VAR"
C'CUSTOM_VAR'
Dcustom_value
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the variable name in code.
Using unquoted values with spaces in .env.
5fill in blank
hard

Fill all three blanks to create a Laravel config entry that uses an environment variable with a default fallback.

Laravel
"'timezone' => env([1], [2]), // Default is [3]"
Drag options to blanks, or click blank then click option'
A'APP_TIMEZONE'
B'UTC'
C"UTC"
D"APP_TIMEZONE"
EUTC
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the environment variable name or default value.
Using single quotes inconsistently.