#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Using .env for Environment Configuration

The .env file holds configuration values that differ between environments — local development, staging, and production — keeping them out of the codebase itself.

What Belongs in .env

APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=secret

Reading Env Values in Config Files

// config/database.php
'password' => env('DB_PASSWORD', ''),

Application code should read values through the config() helper — never call env() directly outside config files — since config caching (covered next) doesn't re-read .env at runtime.

Keeping .env Out of Version Control

The .env file should always be listed in .gitignore, with a .env.example committed instead to document which variables a fresh setup needs.

Multiple Environments

Different .env files (or environment variables set at the hosting-platform level) let the same codebase behave differently across local, staging, and production without any code changes.

With configuration handled safely, the next step is making sure Laravel doesn't have to re-read and re-process all of that on every single request.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course