Package Data | |
---|---|
Maintainer Username: | ferrisutanto |
Maintainer Contact: | greenhouseprod@gmail.com (Ferri Sutanto) |
Package Create Date: | 2016-09-09 |
Package Last Update: | 2017-01-11 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:08:16 |
Package Statistics | |
---|---|
Total Downloads: | 49 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 5 |
Total Forks: | 0 |
Total Open Issues: | 1 |
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'); // default
Determine if setting exists.
Settings::has('key'); // true
Settings::has('keyNotExists'); // false
Remove 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'); // null
Resolve 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'); // value
Get setting value with extra columns
settings($key, $default, ['tenant_id' => 1])
composer install
vendor/bin/phpunit
This package was inspired by these great packages