PHPackages                             sachingk/laravel-kvpair - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sachingk/laravel-kvpair

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sachingk/laravel-kvpair
=======================

KV Pair System For Laravel

v0.1(9y ago)312MITPHP

Since Feb 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/sachingk/laravel-kvpair)[ Packagist](https://packagist.org/packages/sachingk/laravel-kvpair)[ RSS](/packages/sachingk-laravel-kvpair/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel KVPair
==============

[](#laravel-kvpair)

KV Pair System For Laravel 5.4

Introduction
------------

[](#introduction)

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.

#### Benefits, Benefits and Benefits

[](#benefits-benefits-and-benefits)

- All your KV Pair are inside on table. Hence you can use them in your SQL joins
- You can give description for every KV Pair
- You can put KV pairs in a group (aka Group them)
- Get the KV pairs ready to bind with select html control
- Multiple Language Support for "select" string

Installation
------------

[](#installation)

Require this package with composer:

```
composer require sachingk/laravel-kvpair
```

After updating composer, add the ServiceProvider to the providers array in config/app.php

### Laravel 5.x:

[](#laravel-5x)

#### Add Service Provider

[](#add-service-provider)

```
 sachingk\kvpair\KVPairServiceProvider::class,
```

#### Add Facade

[](#add-facade)

If you want to use the facade , add this to your facades in app.php:

```
 "KVPair"=> sachingk\kvpair\Facade\kvpair::class,
```

#### Make Migration

[](#make-migration)

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.

Usage
-----

[](#usage)

This KV pair system provides 4 set of functions to work with KV store.

- Add
- Get
- Delete
- Count

#### Adding KV Pair to store

[](#adding-kv-pair-to-store)

You can add KV Pair to the store in 2 ways

- One at a time
- Bulk Addition

##### One at a time

[](#one-at-a-time)

This take 4 parameters

```
KVPair::addKVPair("key","value","description","group")
```

- 1st Parameter : key - Key of the KV Pair
- 2nd Parameter : value - Value of KV Pair
- 3rd Parameter : description - Description of KV Pair (can be empty)
- 4th Parameter : group - Group of the KV Pair which it belongs to

This function will return true or false. While True stands for successful addition, False stands for failure. False will be returned if

- All the required parameters are not set
- A KV pair already exists with the same key

##### Bulk Addition

[](#bulk-addition)

This take 1 parameter which is an array.

```
KVPair::addKVPairs("key","value","description","group")
```

- 1st Parameter : $KeyValuePairs - Array of KV Pairs. The array follow the below structure

```
 [
   ["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

- All the required parameters are not set
- Any of the KV pair are not set in terms of key, value or group
- A KV pair already exists with the same key

#### Retrieving KV Pair from store

[](#retrieving-kv-pair-from-store)

You can add KV Pair to the store in 5 ways

- Get By Single Key
- Get By Multiple Keys
- Get By Single Group
- Get By Multiple Groups
- Get All KV Pairs for KV Store

##### Get By Single Key

[](#get-by-single-key)

This take 1 parameter i.e key

```
KVPair::getKVPairByKey($key)
```

- 1st Parameter : key - the key name

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"
}
```

##### Get By Multiple Keys

[](#get-by-multiple-keys)

This take 2 parameter

```
KVPair::getKVPairByKeys($keys)
```

- 1st Parameter : keys - Array of keys
- 2nd Parameter : forDropDown - boolean (optional, false by default)

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.

##### Get By Single Group

[](#get-by-single-group)

This take 2 parameter

```
KVPair::getKVPairByGroup($group)
```

- 1st Parameter : group - the group name as string
- 2nd Parameter : forDropDown - boolean (optional, false by default)

The output follows the same pattern as defined in **Get By Multiple Keys**  (above)

##### Get By Multiple Groups

[](#get-by-multiple-groups)

This take 2 parameter

```
KVPair::getKVPairByGroups($groups)
```

- 1st Parameter : group - array of group names
- 2nd Parameter : forDropDown - boolean (optional, false by default)

The output follows the same pattern as defined in **Get By Multiple Keys**  (above)

##### Get All KV Pairs for KV Store

[](#get-all-kv-pairs-for-kv-store)

This take 1 parameter

```
KVPair::getKVPairByGroups()
```

- 1st Parameter : forDropDown - boolean (optional, false by default)

The output follows the same pattern as defined in **Get By Multiple Keys**  (above)

#### Deleting KV Pair from store

[](#deleting--kv-pair-from-store)

You can delete KV Pair from store in 5 ways

- Delete By Single Key
- Delete By Multiple Keys
- Delete By Single Group
- Delete By Multiple Groups
- Delete All KV pair from store

##### Delete By Single Key

[](#delete-by-single-key)

This take 1 parameter i.e key

```
KVPair::deleteKVPairByKey($key)
```

- 1st Parameter : key - the key name

This function will return true or false. While True stands for successful addition, False stands for failure. False will be returned if

- KV pair don't exists in the store
- The parameter is not passed

##### Delete By Multiple Key

[](#delete-by-multiple-key)

This take 1 parameter

```
KVPair::deleteKVPairByKeys($keys)
```

- 1st Parameter : key - array of key names

This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if

- KV pair don't exists in the store
- The parameter is not passed

##### Delete By Single Group

[](#delete-by-single-group)

This take 1 parameter

```
KVPair::deleteKVPairByGroup($group)
```

- 1st Parameter : group - name of the group

This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if

- KV pair don't exists in the store
- The parameter is not passed

##### Delete By Single Group

[](#delete-by-single-group-1)

This take 1 parameter

```
KVPair::deleteKVPairByGroups($groups)
```

- 1st Parameter : group - name of the group

This function will return true or false.While True stands for successful addition, False stands for failure. False will be returned if

- KV pair don't exists in the store
- The parameter is not passed

##### Delete All KV pair from store

[](#delete-all-kv-pair-from-store)

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

- KV store is already empty

#### Counting KV Pair in the store

[](#counting-kv-pair-in-the-store)

You can delete KV Pair from store in 3 ways

- Count By Single Group
- Count By Multiple Groups
- Count All KV pair in the store

##### Count By Single Group

[](#count-by-single-group)

This take 1 parameter

```
KVPair::countKVPairByGroup($group)
```

- 1st Parameter : group - name of the group

This function will return the integer value.

##### Count By Multiple Groups

[](#count-by-multiple-groups)

This take 1 parameter

```
KVPair::countKVPairByGroups($groups)
```

- 1st Parameter : group - array of group names

This function will return the integer value.

##### Count All KV pair in the store

[](#count-all-kv-pair-in-the-store)

This take no parameter

```
KVPair::countAllKVPair()
```

This function will return the integer value.

Configuration
-------------

[](#configuration)

This package has 2 configurations which developer can set based on their choice.

- alwaysGetForDropdown
- selectKey

##### alwaysGetForDropdown

[](#alwaysgetfordropdown)

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

##### selectKey

[](#selectkey)

Value assigned to this will used as a key for select when rendering the get function for dropdown.

### How to configure

[](#how-to-configure)

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.

Multilingual
------------

[](#multilingual)

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)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3364d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b04a0ee95641dfde216e422c2b6fca454c244d490f9f00ef89140f8711538aa?d=identicon)[sachingk](/maintainers/sachingk)

---

Top Contributors

[![sachingk](https://avatars.githubusercontent.com/u/1048263?v=4)](https://github.com/sachingk "sachingk (7 commits)")

---

Tags

key-valuekeyvaluestorekvstorelaravel-5-packagelaravel-frameworklaravel-kvpair

### Embed Badge

![Health badge](/badges/sachingk-laravel-kvpair/health.svg)

```
[![Health](https://phpackages.com/badges/sachingk-laravel-kvpair/health.svg)](https://phpackages.com/packages/sachingk-laravel-kvpair)
```

###  Alternatives

[tapp/laravel-airtable

Laravel Airtable SDK

113229.1k](/packages/tapp-laravel-airtable)[codeigniter4/tasks

Task Scheduler for CodeIgniter 4

117149.1k1](/packages/codeigniter4-tasks)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)[derhansen/sf_event_mgt

Configurable event management and registration extension based on ExtBase and Fluid

64313.9k6](/packages/derhansen-sf-event-mgt)[wyrihaximus/react-child-process-messenger

Messenger decorator for react/child-process

32279.4k4](/packages/wyrihaximus-react-child-process-messenger)[elisdn/php-hydrator

Simple object hydrator

4160.4k](/packages/elisdn-php-hydrator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
