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.
- PHP >= 7.1.3
- Laravel >= 5.6
- Bootstrap >= 4.0
-
- 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);
- 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
Add middleware in the .env
file, separated by commas, for example:
KEY_VALUE_MIDDLEWARE=web,auth