GithubHelp home page GithubHelp logo

laravel-5-cascading-config's Introduction

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.

laravel-5-cascading-config's People

Contributors

phanan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.