Reputation: 3082
My laravel 4 project has multiple environments set up.
The environments setup are: development is called 'development' and production is called 'production'. In my app/config folder, I have two extra folders. One for each name of the environment.
See screenshot:
Inside these folders I have separate config files for database.php and app.php. These are working as expected. Laravel uses my local database configuration when running locally and production when running live.
Now, I've added a new package which requires a config file. This resides in /app/config/packages/greggilbert/config.php
.
I need to be able to set different config files the same way I do for the database. So, I assumed creating the same file structure in /development
or /production
would work, but this does not seem to be the case.
Here is a new screenshot:
Upvotes: 0
Views: 999
Reputation: 15220
Package-related, environment-specific configuration files have to be placed in the package's directory within a subdirectory named after the environment. So in your case this would be
app
- config
- packages
- greggilbert
- recaptcha
- development
- config.php
- production
- config.php
But it can get really ugly and cumbersome in some cases. This can be solved in a (in my opinion) cleaner and more elegant way through enviroment files in your application root directory:
/.env.development.php
<?php
return [
// any configuration settings for your local environment
'RECAPTCHA_TEMPLATE' => 'customCaptcha',
'RECAPTCHA_LANGUAGE' => 'en',
];
That way, you could leave the package directory as it is:
app
- config
- packages
- greggilbert
- recaptcha
- config.php
Laravel will load the environment file according to the environment and make the environment variables globally available through getenv()
. So now you could just grab the specified template for the current environment with getenv('RECAPTCHA_TEMPLATE')
from the config.php.
Upvotes: 1