Environment Variables

Using the app:install Artisan command you can install the dotenv component:

php <your-app-name> app:install dotenv

The dotenv component allows you to load environment variables from a .env file. And behind the scenes, it's based on the DotEnv PHP package.

After installing the component, an empty .env.example will be create on the root of your project, and you should rename it manually to .env.

Assuming that your .env contains:

SECRET_KEY=234567

You can access those variables using the env() helper:

echo env('SECRET_KEY') // outputs 234567

After building your application

After your application is built, you may create a .env file, in the same directory as your build.

.
├── .env
└── application