Skip to content

Laravel – .env Variables

Last updated on February 17, 2018

Laravel utilizes the DotEnv PHP library by Vance Lucas. Using this library we can easily configure the application settings and we can have different configuration values based on the environment where the application is running.

The root directory of your application will contain the .env file (if not copy and rename .env.example to .env)and this file should not be committed to your application’s source control since each developer/server using your application could require a different environment configuration.

If you are developing with a team, you may wish to continue including a .env.example file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application

You may also create a .env.testing file. This file will override values from the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.

There may be in situations where you need to have similar settings that may be different from your production environment but while you’re developing you might want the values to be the same.

Such as email addresses you might want from the name and from the email address to be the same.

[email protected]
[email protected]

If these are the same values you can use this simple trick to set up variables in your eve file so you do not need to repeat yourself.

[email protected]
MAIL_FROM_EMAIL=${MAIL_FROM_NAME}
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments