This is Laravel 5 package for storing dynamic config in database.
Table of content
- Dynamic config stored in database
- Easily add new keys
Via composer
run following command in your project root:
composer require vi-kon/laravel-db-config
In your Laravel 5 project add following lines to app.php
:
// to app.php's providers array
'ViKon\DbConfig\DbConfigServiceProvider',
To install database migration file simple call following commands:
php artisan vendor:publish --provider=ViKon\DbConfig\DbConfigServiceProvider
php artisan migrate
This will install create_config_table
migration file to application database/migrations
directory and create new config
table in default database.
Getting data from database is simple:
$value = config_db('key');
Provide default value if key not exists in database
$value = config_db('key', 'default_value');
If no parameter provided to config_db
function, then it returns ViKon\DbConfig\DbConfig
instance.
// Get value by key
$value = config_db()->get('key');
// Get value by key with default value
$value = config_db()->get('key', 'default_value');
Set values to database is easy simple call config_db
function with no parameter and after it call set
method.
config_db()->set('key', 'value');
###Organize config keys
For better maintenance there is a support organizing config values to groups. To get or set config value to group simple use {group}::{key}
schema as key.
// Gets 'db' group username value
$value = config_db('db::username');
This package is licensed under the MIT License