2017 © Pedro Peláez
 

library quick-dict

A Laravel package for create migration and seeder from key-value data.

image

sukohi/quick-dict

A Laravel package for create migration and seeder from key-value data.

  • Friday, April 13, 2018
  • by Sukohi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

QuickDict

A Laravel package for create migration and seeder from key-value data. (This is maintained under Laravel 5.6), (*1)

Installation

Execute composer command., (*2)

composer require sukohi/quick-dict:1.*

And publish a configuration file., (*3)

php artisan vendor:publish --provider="Sukohi\QuickDict\QuickDictServiceProvider"

Now you should have quick-dict.php in /config., (*4)

Usage

Please add key-value data in quick-dict.php like so., (*5)

return [
    'months' => [
        1 => 'January',
        2 => 'February',
        3 => 'March',
        4 => 'April',
        5 => 'May',
        6 => 'June',
        7 => 'July',
        8 => 'August',
        9 => 'September',
        10 => 'October',
        11 => 'November',
        12 => 'December'
    ]
]

Then run the next command to add the data into DB., (*6)

php artisan dict

This means that QuickDict creates migration and seeder then run them., (*7)

Add new key-value data

When you'd like to add new key-value data like so, also run php artisan dict. Existing table will be ignored., (*8)

return [
    'months' => [
        1 => 'January',
        2 => 'February',
        3 => 'March',
        4 => 'April',
        5 => 'May',
        6 => 'June',
        7 => 'July',
        8 => 'August',
        9 => 'September',
        10 => 'October',
        11 => 'November',
        12 => 'December'
    ],
    'weekday_names' => [    // New
        0 => 'Sunday',
        1 => 'Monday',
        2 => 'Tuesday',
        3 => 'Wednesday',
        4 => 'Thursday',
        5 => 'Friday',
        6 => 'Saturday',
    ]
]

Update key-value data

When you change key-value data of existing table, use php artisan dict:refresh command. The command has two ways., (*9)

First one is with table name., (*10)

php artisan dict:refresh months

And another one is width --all option., (*11)

php artisan dict:refresh --all

Of cause this means all of your key-value data will be replaced with new ones., (*12)

Recommendation

After running php artisan dict command, I recommend you to add new Seeder(s) into database/seeds/DatabaseSeeder so that you can manage your key-value data also through seeder commnd like php artisan migrate:fresh --seed., (*13)

Retrieve key-value data

You can use dict() helper function for retrieving the key-value data like so., (*14)

$collection = dict('months');

// or

echo dict('months.1');  // January

// or

$collection = dict(['months', 'weekday_names']);
echo $collection->toJson();

License

This package is licensed under the MIT License., (*15)

Copyright 2018 Sukohi Kuhoh, (*16)

The Versions

13/04 2018

dev-master

9999999-dev

A Laravel package for create migration and seeder from key-value data.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

13/04 2018

1.0.x-dev

1.0.9999999.9999999-dev

A Laravel package for create migration and seeder from key-value data.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

13/04 2018

1.0.1

1.0.1.0

A Laravel package for create migration and seeder from key-value data.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

13/04 2018

1.0.0

1.0.0.0

A Laravel package for create migration and seeder from key-value data.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi