sukohi/quick-dict 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sukohi/quick-dict

Composer 安装命令:

composer require sukohi/quick-dict

包简介

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

README 文档

README

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

Installation

Execute composer command.

composer require sukohi/quick-dict:1.*

And publish a configuration file.

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

Now you should have quick-dict.php in /config.

Usage

Please add key-value data in quick-dict.php like so.

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.

php artisan dict

This means that QuickDict creates migration and seeder then run them.

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.

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.

First one is with table name.

php artisan dict:refresh months

And another one is width --all option.

php artisan dict:refresh --all

Of cause this means all of your key-value data will be replaced with new ones.

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.

Retrieve key-value data

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

$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.

Copyright 2018 Sukohi Kuhoh

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固