Laravel database configuration requires setting the host, database, username and password for a mysql or postgres database in config/database.php. However when adding a database in Heroku, it is specified as a single URL usually set as an environment variable DATABASE_URL. I looked in the Laravel database connectors but found no solution to use the URL, so I set each host, database, etc. Is there a way to use the URL directly?
3
votes
1 Answers
4
votes
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$host = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$database = substr($url["path"], 1);
More background info about using mysql/cleardb on heroku: http://mattstauffer.co/blog/laravel-on-heroku-using-a-mysql-database