Laravel 5 persistent settings in database package
Support Laravel 5.1, 5.2, 5.3
composer require ferri/laravel-settings
And add service provider to you config/app.php
...
Ferri\LaravelSettings\ServiceProvider::class,
...
Publish config and migration
php artisan vendor:publish --provider="Ferri\LaravelSettings\ServiceProvider" --tag=config
php artisan vendor:publish --provider="Ferri\LaravelSettings\ServiceProvider" --tag=migrations
You can disable cache when get setting value. Default is true. Cache is inherit from active driver in config/cache.php
'cache' => false,Set setting value
Settings::set('key', 'value');
Settings::set('keyArray', ['arrayKey' => 'arrayValue']);Get setting value
Settings::get('key'); // value
Settings::get('keyArray'); // ['arrayKey' => 'arrayValue']
Settings::get('keyNotExists', 'default'); // defaultDetermine if setting exists.
Settings::has('key'); // true
Settings::has('keyNotExists'); // falseRemove setting from database and cache if enabled
Settings::forget('key');Remove all setting from database (truncate) and cache if enabled
Settings::truncate();Sometime you want to specify some criteria for each your setting. This columns will be added to each query.
Extra columns always resetted after call of one these methods set, get, has, forget.
Settings::setExtraColumns(['tenant_id' => 1])->set('site_title', 'Awesome Blog');
Settings::setExtraColumns(['tenant_id' => 1])->get('site_title'); // Awesome Blog
Settings::setExtraColumns(['tenant_id' => 2])->get('site_title'); // nullResolve settings service instance.
settings();Set setting value
settings([$key => $value]);Set setting value with extra columns
settings([$key => $value], null, ['tenant_id' => 1])Get setting value
settings('key'); // valueGet setting value with extra columns
settings($key, $default, ['tenant_id' => 1])
composer install
vendor/bin/phpunit
This package was inspired by these great packages