itsdamien/laravel-heroku-config-parser

This package is abandoned and no longer maintained. No replacement package was suggested.

Parse Heroku config vars like DATABASE_URL or REDIS_URL to work with Laravel.

v1.1 2017-08-23 15:37 UTC

This package is auto-updated.

Last update: 2020-01-06 11:08:23 UTC


README

Latest Stable Version Total Downloads License Build Status Maintainability Test Coverage StyleCI

Parse Heroku config vars like DATABASE_URL or REDIS_URL to work with Laravel.

Important

Due to a breaking change in Laravel 5.8 (thanks https://github.com/mathieutu for the feedback), you can use this method to achieve the same goal:

https://github.com/itsDamien/laravel-heroku-config-parser/issues/2#issuecomment-469709141

Breaking change:

https://github.com/laravel/framework/issues/27695

https://github.com/laravel/docs/pull/5039

Why

When adding a database or a redis server to your Heroku app, Heroku add a URL config var like this: DATABASE_URL=postgres://usr:pwd@localhost:5432/hellodb

Unfortunately, Laravel can't read this var, so you probably parsed it manually like this:

heroku config:set DB_CONNECTION=pgsql
heroku config:set DB_HOST=localhost
heroku config:set DB_PORT=5432
heroku config:set DB_DATABASE=hellodb
heroku config:set DB_USERNAME=usr
heroku config:set DB_PASSWORD=pwd

Laravel Heroku Config Parser parse automatically your DATABASE_URL and REDIS_URL to dynamically set all vars needed by Laravel (see the list).

Installation

Installation using composer:

composer require itsdamien/laravel-heroku-config-parser

Heroku

Add these config vars:

heroku config:set KEY_DATABASE=DATABASE_URL
heroku config:set KEY_REDIS=REDIS_URL

Laravel

Add this block code to the top of your config/database.php:

if (class_exists('\ItsDamien\Heroku\Config\Parse')) {
    new \ItsDamien\Heroku\Config\Parse();
}

Enjoy !

ENV vars created

DATABASE_URL postgres://usr:pwd@ec2-s1:5432/db1 mysql://usr:pwd@ec2-s2:3306/db2
DB_CONNECTION pgsql mysql
DB_HOST       ec2-s1                         ec2-s2                    
DB_PORT       5432                           3306                      
DB_DATABASE db1 db2
DB_USERNAME usr usr
DB_PASSWORD   pwd                           pwd                        
REDIS_URL redis://h:pwd@ec2-s1:11469
REDIS_HOST ec2-s1
REDIS_PORT 11469
REDIS_PASSWORD pwd

Customize the config var who will be parsed

You can select wich config var will be parsed by setting KEY_DATABASE and KEY_REDIS like this:

heroku config:set KEY_DATABASE=HEROKU_POSTGRESQL_BRONZE
heroku config:set KEY_REDIS=REDIS_URL_BACKUP

License

Laravel Heroku Config Parser is open-sourced software licensed under the MIT license