stevenlei / laravel-keyvalue
Laravel KeyValue
Installs: 76
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: ^7.1.3
- laravel/framework: ^5.6
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.4
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2023-06-13 18:37:48 UTC
README
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist stevenlei/laravel-keyvalue "^1.0"
or add
"stevenlei/laravel-keyvalue": "^1.0"
to the require section of your composer.json
file.
Environment Requirements
- PHP >= 7.1.3
- Laravel >= 5.6
- Bootstrap >= 4.0
Usage
-
- Registering Provider in the
config/app.php
configuration file:
- Registering Provider in the
'providers' => [ // ... StevenLei\LaravelKeyValue\ServiceProvider::class, ], 'aliases' => [ // ... 'KeyValue' => StevenLei\LaravelKeyValue\Facade::class, ],
-
- Create configuration files:
php artisan vendor:publish --provider="StevenLei\LaravelKeyValue\ServiceProvider"
-
- The configuration file:
config/keyvalue.php
, modify the configuration items in the.env
file, for example:
- The configuration file:
KEY_VALUE_PREFIX=KV_
KEY_VALUE_TTL=7200
KEY_VALUE_USERNAME=username
KEY_VALUE_MIDDLEWARE=web,auth
-
- How to get the key's value in the program?
# Get the string value StevenLei\LaravelKeyValue\Facade::getValue($key, $throwException = true); # Get the json object StevenLei\LaravelKeyValue\Facade::getJsonValue($key, $throwException = true); # Get the array StevenLei\LaravelKeyValue\Facade::getArrayValue($key, $throwException = true); # Get the collection StevenLei\LaravelKeyValue\Facade::getCollectionValue($key, $throwException = true);
or use the helper function
kv_get($key, $type = KeyValue::TYPE_STRING, $throwException = true);
Routes
- Index page
/key-value/index
- alias:
keyvalue.index
- Create page or store resource
/key-value/create
- alias:
keyvalue.create
- Update page or update resource
/key-value/update
- alias:
keyvalue.update
- Delete resource(only soft delete)
/key-value/delete
- alias:
keyvalue.delete
Middleware
Add middleware in the .env
file, separated by commas, for example:
KEY_VALUE_MIDDLEWARE=web,auth