Parse Heroku config vars like DATABASE_URL
or REDIS_URL
to work with Laravel.
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:
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 using composer:
composer require itsdamien/laravel-heroku-config-parser
Add these config vars:
heroku config:set KEY_DATABASE=DATABASE_URL
heroku config:set KEY_REDIS=REDIS_URL
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 !
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 |
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
Laravel Heroku Config Parser is open-sourced software licensed under the MIT license