softinklab/laravel-keyvalue-storage
Composer 安装命令:
composer require softinklab/laravel-keyvalue-storage
包简介
Key-Value Storage for Laravel using Database or JSON File
README 文档
README
Introduction
Laravel Key Value Storage is an easy and simple package to store key-value data globally in Laravel. This package supports both Database and JSON File as storage methods. This package also comes with helper which simplify your key-value storage access in Code as well as in Blade Template.
Installation
You can install the package via composer:
composer require softinklab/laravel-keyvalue-storage
Setup
This package supports the auto-discovery feature of Laravel 5.5 and above, So skip these Setup instructions if you're using Laravel 5.5 and above.
In config/app.php add the following :
1 - Service Provider to the providers array :
SoftinkLab\LaravelKeyvalueStorage\KeyValueStorageServiceProvider::class,
2 - Class alias to the aliases array :
'KVOption' => SoftinkLab\LaravelKeyvalueStorage\Facades\KVOption::class,
3 - Publish the config file
php artisan vendor:publish --provider="SoftinkLab\LaravelKeyvalueStorage\KeyValueStorageServiceProvider"
4 - Migrate database tables
php artisan migrate
Configuration
You can change the settings in config/kvstorage.php.
Example : Databse Storage
'method' => 'database',
'table_name' => 'kv_storage',
Example : File Storage
'method' => 'file',
'disk' => 'local',
'path' => 'kvstorage/',
Usage
Using FACADE
use SoftinkLab\LaravelKeyvalueStorage\Facades\KVOption; // Check is the option exists. Return true if found. KVOption::exists('key'); // Get the option value. KVOption::get('key'); // Get the option value. Default value is optional. If option not found default value is returned. KVOption::get('key', 'default value'); // Add new option. Comment is optional. Comment is only working in Database Mode. KVOption::set('key', 'value', 'comment'); // Add multiple options. // Example Input => [['key1', 'value1', 'comment1'],['key2', 'value2', 'comment2']] KVOption::setArray('array'); // Increment the value of a given key and return it as integer. Factor is used to determine the step. Default is one. KVOption::increment('key', 'factor'); // Decrement the value of a given key and return it as integer. Factor is used to determine the step. Default is one. KVOption::decrement('key', 'factor'); // Delete an option KVOption::remove('key');
Using Helper
// Check is the option exists. Return true if found. kvoption_exists('someKey'); // Get the option value. kvoption('key'); // Get the option value. Default value is optional. If option not found default value is returned. kvoption('key', 'default value'); // Add new option. Comment is optional. Comment is only working in Database Mode. kvoption(['key','value', 'comment']); // Add multiple options. // Example Input => [['key1', 'value1', 'comment1'],['key2', 'value2', 'comment2']] kvoption('array');
Blade Templates
You can use kvoptions() helper to access key-values in Blade Templates.
{{kvoption('key')}}
Console
There are some console commands to perform actions.
Create an Option
php artisan kvoption:create {key} {value} --comment={comment}
comment is optional.
Delete an Option
php artisan kvoption:delete {key}
Credits
This package is inspired by,
- spatie/valuestore by Spatie
- appstract/laravel-options by Appstract
Contributing
Contributions are welcome! Please refer CONTRIBUTING for details.
License
Laravel Key Value Storage is open-sourced software licensed under the Apache 2.0 License.
统计信息
- 总下载量: 10.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-22