0
0
Laravelframework~20 mins

.env file and environment variables in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Env Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Laravel config call?
Given the .env file contains APP_NAME=MyApp, what will config('app.name') return in a Laravel controller?
Laravel
<?php
// .env file
APP_NAME=MyApp

// In a controller method
return config('app.name');
A"MyApp"
B"APP_NAME"
Cnull
D"app.name"
Attempts:
2 left
💡 Hint
Remember Laravel loads .env values into config files during bootstrap.
📝 Syntax
intermediate
2:00remaining
Which .env syntax is correct for setting a boolean?
You want to set APP_DEBUG to true in your .env file. Which line is correct?
AAPP_DEBUG=true
BAPP_DEBUG=True
CAPP_DEBUG=1
DAPP_DEBUG='true'
Attempts:
2 left
💡 Hint
.env files treat all values as strings; Laravel converts some values automatically.
🔧 Debug
advanced
2:00remaining
Why does env('MY_VAR') return null despite being set in .env?
You set MY_VAR=hello in your .env file but env('MY_VAR') returns null in your Laravel app. What is the most likely cause?
AThe variable name is case sensitive and should be lowercase
BThe .env file is missing the closing semicolon
CYou need to restart the web server for .env changes to apply
DYou forgot to run <code>php artisan config:cache</code> after changing .env
Attempts:
2 left
💡 Hint
Think about Laravel's config caching behavior.
state_output
advanced
2:00remaining
What is the value of config('database.default') after this .env change?
If your .env file has DB_CONNECTION=pgsql and your config/database.php uses env('DB_CONNECTION', 'mysql'), what will config('database.default') return?
A"mysql"
B"pgsql"
Cnull
D"DB_CONNECTION"
Attempts:
2 left
💡 Hint
Check how env fallback values work.
🧠 Conceptual
expert
2:00remaining
Why should sensitive keys not be committed to version control in .env?
Which is the best reason to exclude .env files containing sensitive keys from version control systems like Git?
ATo prevent exposing secrets like API keys and passwords publicly
BTo avoid merge conflicts when multiple developers edit the same .env
CBecause Laravel automatically regenerates .env files on deployment
DBecause .env files are too large and slow down Git operations
Attempts:
2 left
💡 Hint
Think about security risks of sharing secrets.