configurationlaravellaravel-4environments

How to get production configuration variables when executing in another environment


In laravel configuration variables can be accessed like this

   Config::get('xxx')

By default it returns the configuration values for the current environment. How do you get configuration data for other environments?


Solution

  • A call to Config::get() will already get you information of your current environment, if you are in dev it will be dev, if you are in production it will be the production data.

    If you need to get a configuration information about another environment you can do by:

    return Config::get('environment/config.name');
    

    Example:

    return Config::get('testing/cache.driver');
    

    If you need to get things from your production environment while being in any other one, I'm afraid you'll have to create a 'production' folder inside your config folder and put those things there:

    app/config/production/database.php
    

    Add to that particular file only what you need to read outside from your environment:

    'default' => 'postgresql',
    

    And then you'll have access to it:

    return Config::get('production/database.default');