Skip to content

Conversation

krzystof
Copy link

This allows to define several .env file, for example .env.testing. That means we could remove the configuration in phpunit,xml and move it to a custom env file.
If a file matching the APP_ENV exists, Laravel will load this file. Else, load the usual .env.

I have found it useful to run behat tests in the browser on a specific database connection (set the APP_ENV on a vhost).

@GrahamCampbell GrahamCampbell changed the title Load custom .env file if it exists [5.2] Load custom .env file if it exists Jan 13, 2016
@taylorotwell
Copy link
Member

I guess I'm confused on how APP_ENV is even going to be set if we haven't loaded the default file yet?

@lucasmichot
Copy link
Contributor

@taylorotwell APP_ENV can be already set as a system variable in php.ini, .profile or another file.
This variable will be set before loading the custom env file

@krzystof what if APP_ENV is set outside the code (eg. APP_ENV=testing) and the .env.testing contains APP_ENV=production ?
What about making APP_ENV immutable ?

@krzystof
Copy link
Author

If an environment variable is already set, the Dotenv load calls does not overwrite existing values.

By default, Dotenv will NOT overwrite existing environment variables that are already set in the environment.

If you want Dotenv to overwrite existing environment variables, use overload instead of load

@taylorotwell In phpunit.xml for example, the APP_ENV is set to testing.

@krzystof
Copy link
Author

@lucasmichot yes makes sense. Cleaner. I will commit this if @taylorotwell plans to merge this PR?

@taylorotwell
Copy link
Member

Can you remove that unrelated test change?

@GrahamCampbell
Copy link
Member

Please squash to one commit and rebase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return void

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants