10
Nov '15

I love most of the new features of Laravel 5, but it definitely has its drawbacks – a specific one as far as I’m concerned is the new way of managing configuration files. In Laravel 4 we all got very accustomed to being able to have a full set of configuration files for each environment, with any level of nesting and complexity we liked, but now everything we want to do on a per-environment basis has to be defined within flat .env files. Having said that I do completely accept that it is better in terms of safety to have a single, non-version-controlled environment config file, rather than a whole bunch which, lets be honest, we all ended up putting under version control, passwords and all!

So in an effort to embrace the new structure whilst maintaining some of the function of the old, I came up with a little script to allow some futher complexity to my .env files. When this is added to the ‘boot’ method of the ‘AppServiceProvider’ class it allows multiple pipe-separated values do be pre-processed into an array within the config structure:

if(env('MY_ENV_VALUE')) {
    config()->set('app.my_env_value', explode('|', env('MY_ENV_VALUE')));
}

Really really simple stuff but good grief does it make a difference!