Package Data | |
---|---|
Maintainer Username: | sachingk |
Maintainer Contact: | sachingk.30@gmail.com (Sachin G Kulkarni) |
Package Create Date: | 2017-02-24 |
Package Last Update: | 2017-02-25 |
Home Page: | http:\\SachinGKulkarni.com |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-13 03:03:40 |
Package Statistics | |
---|---|
Total Downloads: | 11 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
KV Pair System For Laravel 5.4
Key-Value pair is being used in most of the cases where only developer will maintain and change the list. Developer usually tends to keep these key-value pair in config file.
While this works just fine in small applications, it becomes very difficult to manage and maintain when the list grows.Unfortunately all application starts small, but grows big very quickly.
To address this problem, I have developed a KV Pair system for laravel framework which stores the KV Pair in the database.
Require this package with composer:
composer require sachingk/laravel-kvpair
After updating composer, add the ServiceProvider to the providers array in config/app.php
sachingk\kvpair\KVPairServiceProvider::class,
If you want to use the facade , add this to your facades in app.php:
"KVPair"=> sachingk\kvpair\Facade\kvpair::class,
Now you need to run artisan migrate command via command line. If you wish to add more columns to the table before migration then run the following command in command line.
php artisan vendor:publish --tag=migrations
Now the migration file get copied to /database/migrations folder. Add any extra columns you need and then run the migrate artisan command.
This KV pair system provides 4 set of functions to work with KV store.
You can add KV Pair to the store in 2 ways
This take 4 parameters
KVPair::addKVPair("key","value","description","group")
This function will return true or false. While True stands for successful addition, False stands for failure. False will be returned if
This take 1 parameter which is an array.
KVPair::addKVPairs("key","value","description","group")
[
["key"=>"key1","value"=>"value1","description"=>"","group"=>"group1"],
["key"=>"key2","value"=>"value2","description"=>"","group"=>"group1"],
];
This function will return true or false. While True stands for successful addition, False stands for failure. False will be returned if
You can add KV Pair to the store in 5 ways
This take 1 parameter i.e key
KVPair::getKVPairByKey($key)
This function will return object of KV Pair that matches the given key or return false if no KV pair found. The object returned will follow below pattern.
{
"key": "A1"
"value": "A1"
"description": ""
"group": "A"
}
This take 2 parameter
KVPair::getKVPairByKeys($keys)
This function will return array of KV Pairs that matches the given keys or return false if no KV pairs found. The output returned will follow below pattern.
array:2 [▼
0 => array:4 [▼
"key" => "A1"
"value" => "A1"
"description" => ""
"group" => "A"
]
1 => array:4 [▼
"key" => "A2"
"value" => "A2"
"description" => ""
"group" => "A"
]
]
However, if the forDropDown is set to true then output returned will follow below pattern.
array:3 [▼
"" => "Select"
"A1" => "A1"
"A2" => "A2"
]
The string "select" can support multiple languages.See the Multilingual Section for more details.
The associated value of "select" can be configurable. See Configuration Section for more details.
This take 2 parameter
KVPair::getKVPairByGroup($group)
The output follows the same pattern as defined in Get By Multiple Keys (above)
This take 2 parameter
KVPair::getKVPairByGroups($groups)
The output follows the same pattern as defined in Get By Multiple Keys (above)
This take 1 parameter
KVPair::getKVPairByGroups()
The output follows the same pattern as defined in Get By Multiple Keys (above)
You can delete KV Pair from store in 5 ways
This take 1 parameter i.e key
KVPair::deleteKVPairByKey($key)
This function will return true or false. While True stands for successful addition, False stands for failure. False will be returned if
This take 1 parameter
KVPair::deleteKVPairByKeys($keys)
This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if
This take 1 parameter
KVPair::deleteKVPairByGroup($group)
This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if
This take 1 parameter
KVPair::deleteKVPairByGroups($groups)
This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if
This take no parameter
KVPair::deleteAllKVPair()
This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if
You can delete KV Pair from store in 3 ways
This take 1 parameter
KVPair::countKVPairByGroup($group)
This function will return the integer value.
This take 1 parameter
KVPair::countKVPairByGroups($groups)
This function will return the integer value.
This take no parameter
KVPair::countAllKVPair()
This function will return the integer value.
This package has 2 configurations which developer can set based on their choice.
If this is set to TRUE all the get functions (except getKVPairByKey) will give the output ready to bind with select html control by default. The $forDropDown parameter passed will be ignored
Value assigned to this will used as a key for select when rendering the get function for dropdown.
To set your configurations , you have to publish the config file using artisan command.
php artisan vendor:publish --tag=config
Now the configuration file get copied to /config folder.You can set your preference here.
This package support multiple language for "select" during the output for dropdown.The translations are take from the language files based on the setting of locale in /Config/app.php.
To start with you can run following publish command to get the default language files of this package.
php artisan vendor:publish --tag=lang
Now the language files get copied to /resources/lang folder. You can add more languages from here by creating individual folder for each language and adding kvpair_lang.php under them.
For now this package creates language file for english and kannada (indian language)