🔴 Laravel
Beginner
What is the .env file in Laravel?
Answer
The .env file stores environment-specific configuration values that should not be committed to version control (database credentials, API keys, mail settings). Laravel uses the dotenv library to load this file. Access values with env("DB_HOST", "localhost") (second argument is the default). Configuration files in config/ use env() to read .env values — always access configuration through config("database.connections.mysql.host") in application code, not env() directly (config values are cached). The .env.example file is committed to VCS as a template. Never commit the actual .env file — add it to .gitignore.