umobi / laravel-settings
Persistent settings manager for laravel, using pivoted database table
2.2.3
2020-03-03 17:31 UTC
Requires
- php: >=5.5.0
- illuminate/cache: >=5.2.0
- illuminate/database: >=5.2.0
- illuminate/support: >=5.2.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.5.3
- mockery/mockery: ^0.9.9
- phpunit/php-code-coverage: ^5.2
- phpunit/phpunit: ^6.1
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-11-08 08:16:48 UTC
README
Persistent Settings Manager for Laravel
- Simple key-value storage
- Support multi-level array (dot delimited keys) structure.
- Localization supported.
Installation
-
Install package
composer require umobi/laravel-settings
-
Edit config/app.php (Skip this step if you are using laravel 5.5+)
service provider:
Umobi\Setting\SettingServiceProvider::class,
class aliases:
'Setting' => Umobi\Setting\SettingFacade::class,
-
Create settings table
php artisan vendor:publish --tag=settings php artisan migrate
Usage
Setting::get('name', 'Computer'); // get setting value with key 'name' // return 'Computer' if the key does not exists Setting::lang('zh-TW')->get('name', 'Computer'); // get setting value with key and language Setting::set('name', 'Computer'); // set setting value by key Setting::lang('zh-TW')->set('name', 'Computer'); // set setting value by key and language Setting::has('name'); // check the key exists, return boolean Setting::lang('zh-TW')->has('name'); // check the key exists by language, return boolean Setting::forget('name'); // delete the setting by key Setting::lang('zh-TW')->forget('name'); // delete the setting by key and language
Dealing with array
Setting::get('item'); // return null; Setting::set('item', ['USB' => '8G', 'RAM' => '4G']); Setting::get('item'); // return array( // 'USB' => '8G', // 'RAM' => '4G', // ); Setting::get('item.USB'); // return '8G'; ``