Configuration

Introduction

Streams uses Laravel config files and environment variables for application-level settings.

Configuration Files

Published configuration files reside in config/streams/.

├── config/streams/
│   ├── core.php
│   ├── api.php
│   └── ui.php

Publishing Configuration

Use the following command to publish configuration files.

php artisan vendor:publish --tag=config

To publish configuration for a specific package use the following:

php artisan vendor:publish --provider=Streams\\Core\\StreamsServiceProvider --tag=config

The above commands will copy configuration files from their package location to the directory mentioned above so that you can modify them directly and commit them to your version control system.

Environment Variables

It is often helpful to have different configuration values based on the environment in which your application is running. For example, you may wish to enable "debug mode" on your local server but not your production server.

The .env File

Environmental variables are defined in the .env file in your project's root directory. In fresh installations, Composer will automatically rename the included .env.example file to .env for you.

You can manually copy and rename, or use php -r "copy('.env.example', '.env');" if the file does not already exist.

Environment Variable Types

Variables in your .env files parse as strings. A couple specific values are worth noting:

EXAMPLE_VAR=        # (string) ''
EXAMPLE_VAR=null    # (null) null

If you need to define an environment variable value containing a space, you may enclose the value in double-quotes.

APP_NAME="Spaghetti + Meatballs"

Retrieving Environment Variables

All environmental variables are available in configuration files by using the env() helper function. An optional second argument allows you to pass a default value.

// config/app.php
'debug' => env('APP_DEBUG', false),

Once passed into a config file, the variable is available using the config() helper function. Again, an optional second argument allows you to specify a default value.

// Retrieve the above 'debug' value:
config('app.debug', false)

Do not version your .env file

The .env file should not be committed to version control. Each developer or server running your application may require a different environment configuration. It is also a security risk if a nefarious character gains access to your version control repository because sensitive data like credentials, API keys, and other configuration would be visible to them.

Hiding Environment Variables from Debug Pages

When an exception is uncaught, and the APP_DEBUG environment variable is true, the debug page will show all environment variables and their assigned values. You may obscure variables by updating the debug_blacklist option in your config/app.php file.

return [

    // ...

    'debug_blacklist' => [
        '_ENV' => [
            'APP_KEY',
            'SECRET_API_KEY',
            'BITCOIN_WALLET_PW',
        ],

        '_SERVER' => [
            'APP_KEY',
            'DB_PASSWORD',
        ],

        '_POST' => [
            'password',
        ],
    ],
];

Learn more about environment configuration in the Laravel docs.