What is the purpose of the .env file?
Answer
Clear, interview-ready explanation
The .env file stores environment-specific configuration values such as the application environment, debug setting, application URL, database connection details, mail credentials, cache driver, and third-party API keys. This lets the same codebase run with different settings in local, staging, and production environments.
Laravel reads environment values into configuration. Application code should normally read values through config() rather than calling env() directly, because configuration may be cached in production. A real .env file can contain secrets and must not be committed to source control; a safe .env.example file should document required keys without exposing credentials.