Configuration
All of the configuration options for the Lumen framework are stored in the file.
You may easily access your configuration values using the global config
helper function from anywhere in your application. The configuration values may be accessed using "dot" syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:
To set configuration values at runtime, pass an array to the config
helper:
It is often helpful to have different configuration values based on the environment the application is running in. For example, you may wish to use a different cache driver locally than you do on your production server. It's easy using environment based configuration.
To make this a cinch, Lumen utilizes the DotEnv PHP library by Vance Lucas. In a fresh Lumen installation, the root directory of your application will contain a .env.example
file. You should rename the .env.example
file to when creating your application.
All of the variables listed in this file will be loaded into the $_ENV
PHP super-global when your application receives a request. The env
function may be used to retrieve the values of your environment variables:
The second value passed to the env
function is the "default value". This value will be used if no environment variable exists for the given key.
If you are developing with a team, you may wish to continue including a file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application.
The current application environment is determined via the APP_ENV
variable from your .env
file. You may access this value via the environment
method on the application instance:
You may also pass arguments to the environment
method to check if the environment matches a given value. If necessary, you may even pass multiple values to the method. If the environment matches any of the given values, the method will return true
: