Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

phanan/laravel-5-cascading-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

laravel-5-cascading-config

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).

Setup

  1. At the same level with your application's config directory, create another with the name config.{APP_ENV} with {APP_ENV} being the value set in .env.
  2. In the new directory, place your corresponding environment config files and variables just like the good old days.
  3. Overwrite app/Providers/ConfigServiceProvider.php, or at least its register() method, into your application.

Notes

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.

Credits

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.

About

Re-enable cascading configuration system in Laravel 5

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages