frenchfrogs / reference
此软件包最新版本(0.1.1)没有可用的许可证信息。
管理参考表
0.1.1
2016-06-30 09:15 UTC
Requires
- frenchfrogs/framework: >=1.8.7
This package is not auto-updated.
Last update: 2024-09-14 19:25:38 UTC
README
管理参考表
# 我不再维护此软件包,我已经迁移到 https://github.com/cotcotquedec/frenchfrogs
该模块的目标是在项目中方便创建引用,为开发者提供最大程度的舒适度。主要功能包括:
- 将参考表统一到一个表中(简化数据模型)
- 开发者可以通过迁移轻松创建新的引用
- 缓存引用,避免频繁调用数据库
- 通过控制台创建文件,方便使用引用
安装
如果您想使用引用导入来在代码中使用常量并启用自动完成
- 确保您在 bootstrap 文件夹中有一个 Ref.php 文件(即使它是空的)
- 在您的 composer.json 文件中添加 "files": ["bootstrap/Ref.php"] 或在 bootstrap/app.php 文件中添加 require_once 文件
composer require frenchfrogs/reference php artisan reference:table php migrate php artisan reference:build
就这样!
它是如何工作的
在数据库中添加引用
在迁移文件中,使用以下代码创建引用
use FrenchFrogs\Models\Reference; //.... Reference::createDatabaseReference($id, $name, $collection, $data = null );
添加了 ref() 函数,以便快速访问集合列表
$reference = \ref('member.status')->getData(); dd($reference);
将显示
array:3 [▼
0 => array:7 [▼
"reference_id" => "MEMBER_STATUS_ACTIVE"
"name" => "Actif"
"collection" => "member.status"
"data" => "null"
"deleted_at" => null
"created_at" => "2016-06-21 11:05:14"
"updated_at" => "2016-06-21 11:05:14"
]
1 => array:7 [▼
"reference_id" => "MEMBER_STATUS_PAID"
"name" => "Payant"
"collection" => "member.status"
"data" => "null"
"deleted_at" => null
"created_at" => "2016-06-21 11:05:14"
"updated_at" => "2016-06-21 11:05:14"
]
2 => array:7 [▼
"reference_id" => "MEMBER_STATUS_DELETED"
"name" => "Supprimé"
"collection" => "member.status"
"data" => "null"
"deleted_at" => null
"created_at" => "2016-06-21 11:05:14"
"updated_at" => "2016-06-21 11:05:14"
]
]
将显示
$reference = \ref('member.status')->pairs(); dd($reference);
array:3 [▼
"MEMBER_STATUS_ACTIVE" => "Actif"
"MEMBER_STATUS_PAID" => "Payant"
"MEMBER_STATUS_DELETED" => "Supprimé"
]