Question

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?

Was it helpful?

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');

OTHER TIPS

You should be able to just do Config::get('xxx');

Unless you are overriding it in your testing/local/develop environments it should always be available. If you are, just remove it from the other envs.

I cannot see why you would define a config variable in another environment but then still need the production config.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top