0
votes

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:

enter image description here

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:

enter image description here

1
You have to put the environment-named folder into the package directory: app/config/packages/<vendor>/<package_name>/<environment>/config.phpQuasdunk
@Quasdunk That works, if you put this as an answer I will accept.CharliePrynn

1 Answers

1
votes

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.