ferri / laravel-settings
Laravel 5 persistent settings in database package
Requires
- php: >=5.6.4
- illuminate/database: 5.1.*|5.2.*|5.3.*
- illuminate/filesystem: 5.1.*|5.2.*|5.3.*
- illuminate/support: 5.1.*|5.2.*|5.3.*
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2024-11-20 23:05:45 UTC
README
Laravel 5 persistent settings in database package
Support Laravel 5.1, 5.2, 5.3
Installation
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
Cache
You can disable cache when get setting value. Default is true
. Cache is inherit from active driver in config/cache.php
'cache' => false,
Usage
Set value
Set setting value
Settings::set('key', 'value'); Settings::set('keyArray', ['arrayKey' => 'arrayValue']);
Get value
Get setting value
Settings::get('key'); // value Settings::get('keyArray'); // ['arrayKey' => 'arrayValue'] Settings::get('keyNotExists', 'default'); // default
Check value
Determine if setting exists.
Settings::has('key'); // true Settings::has('keyNotExists'); // false
Forget value
Remove setting from database and cache if enabled
Settings::forget('key');
Flush settings
Remove all setting from database (truncate) and cache if enabled
Settings::truncate();
Set Extra Columns
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
Helpers
Settings Instance
Resolve settings service instance.
settings();
Set value
Set setting value
settings([$key => $value]);
Set setting value with extra columns
settings([$key => $value], null, ['tenant_id' => 1])
Get value
Get setting value
settings('key'); // value
Get setting value with extra columns
settings($key, $default, ['tenant_id' => 1])
Testing
composer install
vendor/bin/phpunit
Inspiration
This package was inspired by these great packages