IMPORTANT: I've moved on to create a package to support cascading configuration in Laravel 5. This repo is only here for historical purpose, and will not be updated or monitored.
The cascading configuration system in Laravel 4 has been removed in L5 in favor of PHP dotenv, the PHP version of the original Ruby dotenv. This simple gist is to re-enable it (and the whole shining flexibility).
- At the same level with your application's
config
directory, create another with the nameconfig.{APP_ENV}
with{APP_ENV}
being the value set in.env
. - In the new directory, place your corresponding environment config files and variables just like the good old days.
- Overwrite
app/Providers/ConfigServiceProvider.php
, or at least itsregister()
method, into your application.
Actually in Laravel 4, the config
directory structure looks like this:
├── app
│ ├── commands
│ ├── config
│ │ ├── api.php
│ │ ├── app.php
│ │ ├── auth.php
│ │ ├── ...
│ │ ├── local
│ │ │ ├── api.php
│ │ │ ├── app.php
│ │ │ ├── ...
In Laravel 5 though, such a structure will trigger a fatal error. Basically L5 is not happy if you have two different files with the same name under its config
directory. So I ended up with this workaround:
├── config
│ ├── api.php
│ ├── app.php
│ ├── auth.php
│ ├── ...
├── config.local
│ ├── app.php
│ └── auth.php
Not the best, but hey.
The initial idea is from Gnuffo1. I replaced array concatenation with array_replace_recursive
to allow nested configuration, fixed said error, and set the repo up.