Skip to content

Commit 6fbcb00

Browse files
author
Kulkarni
committed
Updated documentation and fixed bugs
1 parent d47977b commit 6fbcb00

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

README.md

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@ KV Pair System For Laravel 5.4
33

44
## Introduction
55

6-
Key-Value pair is being used in most of the cases where only developer will maintain & change the list. Developer usually tends to keep these key-value pair config file.
6+
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 config file.
77

8-
While this works just fine in small applications, it becomes very difficult to manage & maintain when the list grows.Unfortunately all application starts small, but grows big very quickly.
8+
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.
99

1010
To address this problem, I have developed a KV Pair system for laravel framework which stores the KV Pair in the database.
1111

12-
#### Benefits, Benefits & Benefits
12+
#### Benefits, Benefits and Benefits
1313
- All your KV Pair are inside on table. Hence you can use them in your SQL joins
1414
- You can give description for every KV Pair
1515
- You can put KV pairs in a group (aka Group them)
1616
- Get the KV pairs ready to bind with select html control
17-
For Example : <select>
18-
<option>Select</option>
19-
<option>In Progress</option>
20-
<option>Completed</option>
21-
</select>
2217
- Multiple Language Support for "select" string
2318

2419

@@ -34,16 +29,29 @@ After updating composer, add the ServiceProvider to the providers array in confi
3429

3530
### Laravel 5.x:
3631

32+
#### Add Service Provider
33+
3734
```php
3835
sachingk\kvpair\KVPairServiceProvider::class,
3936
```
4037

38+
#### Add Facade
39+
4140
If you want to use the facade , add this to your facades in app.php:
4241

4342
```php
4443
"KVPair"=> sachingk\kvpair\Facade\kvpair::class,
4544
```
4645

46+
#### Make Migration
47+
48+
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.
49+
50+
```php
51+
php artisan vendor:publish --tag=migrations
52+
```
53+
54+
Now the migration file get copied to /database/migrations folder. Add any extra columns you need and then run the migrate artisan command.
4755

4856
## Usage
4957

@@ -347,5 +355,38 @@ KVPair::countAllKVPair()
347355
This function will return the integer value.
348356

349357
## Configuration
358+
This package has 2 configurations which developer can set based on their choice.
359+
360+
- alwaysGetForDropdown
361+
- selectKey
362+
363+
##### alwaysGetForDropdown
364+
If this is set to TRUE all the get functions (except getKVPairByKey) will give the output ready to
365+
bind with select html control by default. The $forDropDown parameter passed will be ignored
366+
367+
##### selectKey
368+
Value assigned to this will used as a key for select when rendering the get function for dropdown.
369+
370+
### How to configure
371+
To set your configurations , you have to publish the config file using artisan command.
372+
373+
```php
374+
php artisan vendor:publish --tag=config
375+
```
376+
```
377+
378+
Now the configuration file get copied to /config folder.You can set your preference here.
379+
380+
## Multilingual
381+
382+
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.
383+
384+
To start with you can run following publish command to get the default language files of this package.
385+
386+
```php
387+
php artisan vendor:publish --tag=lang
388+
```
350389

390+
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.
351391

392+
For now this package creates language file for english and kannada (indian language)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
],
3131
"post-autoload-dump": [
32-
"sachingk\\kvpair\\install::postPackageInstall"
32+
3333
]
3434

3535
}

src/kvpair.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function getKVPairByKeys($keys, $forDropDown = false)
9595
if ($forDropDown == true) {
9696
$Pairs = array($selectKey => $selectTxt) + KVPairModel::whereIn("key", $keys)->pluck("key", "value")->toArray();
9797
} else {
98-
$Pairs = KVPairModel::all(["key", "value", "description", "group"])->whereIn("key", $keys)->toArray();
98+
$Pairs = KVPairModel::all()->whereIn("key", $keys)->toArray();
9999
}
100100
return (isset($Pairs) == true && !empty($Pairs) ? $Pairs : false);
101101

@@ -118,7 +118,7 @@ public static function getKVPairByGroup($group, $forDropDown = false)
118118
if ($forDropDown == true) {
119119
$Pairs = array('' => $selectTxt) + KVPairModel::where("group", "=", $group)->pluck("key", "value")->toArray();
120120
} else {
121-
$Pairs = KVPairModel::all(["key", "value", "description", "group"])->where("group", "=", $group)->toArray();
121+
$Pairs = KVPairModel::all()->where("group", "=", $group)->toArray();
122122
}
123123
return (isset($Pairs) == true && !empty($Pairs) ? $Pairs : false);
124124
}
@@ -140,7 +140,7 @@ public static function getKVPairByGroups($groups, $forDropDown = false)
140140
if ($forDropDown == true) {
141141
$Pairs = array($selectKey => $selectTxt) + KVPairModel::whereIn("group", $groups)->pluck("key", "value")->toArray();
142142
} else {
143-
$Pairs = KVPairModel::all(["key", "value", "description", "group"])->whereIn("group", $groups)->toArray();
143+
$Pairs = KVPairModel::all()->whereIn("group", $groups)->toArray();
144144
}
145145
return (isset($Pairs) == true && !empty($Pairs) ? $Pairs : false);
146146
}
@@ -161,7 +161,7 @@ public static function getAllKVPair($forDropDown = false)
161161
if ($forDropDown == true) {
162162
$Pairs = array($selectKey => $selectTxt) + KVPairModel::pluck("key", "value")->toArray();
163163
} else {
164-
$Pairs = KVPairModel::all(["key", "value", "description", "group"])->toArray();
164+
$Pairs = KVPairModel::all()->toArray();
165165
}
166166

167167
return (isset($Pairs) && !empty($Pairs) == true ? $Pairs : false);

0 commit comments

Comments
 (0)