Note: This is a fork from https://bitbucket.org/hailwoodnz/database-config-loader/overview
Database Config Loader
is a composer package for the Laravel PHP Framework that works in tandem with the default config package to allow developers to easily add user-configurable settings to their app and packages.
- Utilizes the same syntax as the Laravel config package (No new syntax to learn)
- Unlike calls to
Config::set()
calls toDBconfig::set()
are persistant! - Backed by Eloquent for the database component means that it works anywhere Laravel does!
- Automatic type serialization means configuration items can be s
string
,integer
,boolean
or evenarray
and the type you save is the type you get back! - Supports nested keys just like the Laravel Config package
- Support for environment based variables
-
- More...
-
Add the package to composer.json
"hailwood/database-config-loader": "dev-master",
-
Add the service provider to your application's
app.php
under theproviders
key'Hailwood\DatabaseConfigLoader\DatabaseConfigLoaderServiceProvider'
-
Add the facade to your application's
app.php
under thealiases
key'DBconfig' => 'Hailwood\DatabaseConfigLoader\Facades\DatabaseConfigLoader'
Set also works to update a configuration item
The set method is used to set configuration options and follows the same standard as the Laravel Config package which means it supports namespacing, groups (aka files), and nested keys.
All DBconfig::set(...)
methods support an optional third parameter $environment
which is the environment the variable key should be used in, these will automatically cascade just like the standard Config package!
This method is actually just a shortcut to DBconfig::set('config.key', 'value')
!
DBconfig::set('key', 'value')
Equivalent to having the following in app/config/config.php
'key' => 'value'
DBconfig::set('group.key', 'value')
Equivalent to having the following in app/config/group.php
'key' => 'value'
DBconfig::set('group.key', 'value', 'local')
Equivalent to having the following in app/config/local/group.php
'key' => 'value'
This method is actually just a shortcut to DBconfig::set('package::config.key', 'value')
!
DBconfig::set('package::key', 'value')
Equivalent to having the following in app/config/packages/vendor/package/config.php
'key' => 'value'
Packages need to be registered with DBconfig, Actually, they do with the standard Config package too, but Laravel handles this for you when you call $this->package(...)
from your service provider!
DBconfig::set('package::group.key', 'value')
Equivalent to having the following in app/config/packages/vendor/package/group.php
'key' => 'value'
DBconfig::set('package::group.key', 'value', 'local')
Equivalent to having the following in app/config/packages/vendor/package/local/group.php
'key' => 'value'
Nested configuration keys are supported when using any of the with group methods. and has [a bit of magic](#30-nested-configuration-keys---a bit of magic)
DBconfig::set('config.key.subKey1.subKey2.subKey3', 'value')
Equivalent to having the following in app/config/config.php
'key' => array(
'subKey1' => array(
'subKey2' => array(
'subKey3' => 'value'
)
)
)
And running:
DBconfig::set('config.key.subKey1.subKey2.subKey4', 'value2')
After the first line would make the equivalent be
'key' => array(
'subKey1' => array(
'subKey2' => array(
'subKey3' => 'value',
'subKey4' => 'value2'
)
)
)
Notice the array above, let's create the initial key shall we?
DBconfig::set('config.key', array(
'subKey1' => array(
'subKey2' => array(
'subKey3' => 'value'
)
)
));
We need to do that because we cannot set a value on something that doesn't exist, so we need to create the path right? wrong! this is a Laravel package, and that is anything but elegant!
So, Database Config Loader
does a bit of magic for you, Just call DBconfig::set('config.key.subKey1.subKey2.subKey3', 'value')
and we'll do the rest!
The get method is used to retrieve configuration options and follows the same standard as the Laravel Config package, which means it supports namespacing, groups (aka files), and nested keys.
The get method is the same as the set
method, except in only takes on parameter, the key, so we won't detail it all here again, instead just view set
above!
::has(), ::hasGroup(),...
Database config loader
supports all method used by the standard Laravel Config package, so view the official Laravel documentation for other methods!