PHPackages                             machaven/laravel-cascading-config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. machaven/laravel-cascading-config

ActivePackage[Utility &amp; Helpers](/categories/utility)

machaven/laravel-cascading-config
=================================

Multiple cascading environmental configuration files support for Laravel 5

1.0(8y ago)18.7k↓16.7%1MITPHPPHP &gt;=5.5.9

Since Nov 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/machaven/laravel-cascading-config)[ Packagist](https://packagist.org/packages/machaven/laravel-cascading-config)[ RSS](/packages/machaven-laravel-cascading-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel 5 Cascading Config Files
================================

[](#laravel-5-cascading-config-files)

Why? - The .env problem
-----------------------

[](#why---the-env-problem)

When continously developing and extending a laravel application, you may find that your .env file becomes large and hard to maintain. When multiple branches with .env changes are deployed, it becomes a nightmare to consolidate all the .env changes and update the live .env file.

This forced me to rethink configuration and what is truly important inside an .env file.

What to keep in your .env file

- Standard laravel .env settings
- Sensitive information, like login credentials for other apis.

What to take out of your .env file

- All custom settings that might seldom change.

Why use cascading config files?
-------------------------------

[](#why-use-cascading-config-files)

1. Cascading configuration files allow you to keep a set of config files for every environment. All environment configs override the base configs in the config folder. This allows you to setup a dynamic config for each environment.
2. Settings changes can be recorded on pull requests. This prevents settings changes from being lost when only changed on the server .env file.

Furthermore if you use the env() function in your config files, it will allow you to override any defaults in the config file with variables from the .env file if they exist.

Install
-------

[](#install)

Install the package through composer

`composer require machaven/laravel-cascading-config`

After installing, add the ServiceProvider to the providers array in app/config/app.php (not required for laravel 5.5+)

`Machaven\LaravelCascadingConfig\CascadingConfigProvider::class,`

How this works
--------------

[](#how-this-works)

The service provider will check if the directory exists for the environment configured in your .env file. If the environment folder exists, then all configuration files will be read from it and merged over the configurations from the config folder.

Example for cascading config files
----------------------------------

[](#example-for-cascading-config-files)

Firstly, create your default config file in the standard laravel config/ folder.

`config/example.php`

Now create a folder to override the example config for an environment. A folder can be created for any environment defined in your APP\_ENV. In this example, we use local:

`config/local/`

Now create another example config in the local folder:

`config/local/example.php`

Example config file contents
----------------------------

[](#example-config-file-contents)

config/example.php

```
