When creating a composer package that is meant to be run in the Laravel 4 framework, I want to create a default database connection set that looks something like this:
// File Location: LARAVEL4_ROOT/vendor/my/package/src/config/database.php
return array(
'connections' => array(
'reporting' => array(
'driver' => 'mysql',
'host' => getenv('REPORTING_HOST'),
'database' => getenv('REPORTING_DBNAME'),
'username' => getenv('REPORTING_USER'),
'password' => getenv('REPORTING_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
According to all the documentation I can find online, once I have registered my project using the Service Provider pattern and call $this->package('my/package')
; Laravel 4 is supposed to magically load this file and give me access to it in the configuration.
And I have verified that I can call
Config::get('package::database.connections.reporting')
and it returns the array above.
However, when I construct my Eloquent Model file, and try to set the connection using
protected $connection = 'package::database.connections.reporting';
It doesn't work. I get an exception saying:
InvalidArgumentException: Database [package::database.connections.reporting] not configured.
Is there some magic string format I need to use to get the Connection Resolver to connect to my database using the default config in my package?
Thanks for your help!