php - 如何制作带有目录(字典)的通用表?
问题描述
我不断地完成这个任务。
我想找到一个一站式的解决方案。
我有几张桌子。它们有一组相同的字段。
表类型_应用程序
id name title
1 game Games
2 app Application
3 arcade Arcade
表 type_tasks
id name title
1 create Create App
2 update Update App
3 publish Publish App
表 status_applications
id name title
1 created Games
2 moderation Moderated application
3 publish Application published
这些目录属于一个表。
表任务
id name title status_id type_task_id type_application_id
1 first_app My First game 3 2 1
2 second_app My Second game 2 3 2
3 third_app My third game 1 1 3
因此,有 4 个模型。
任务模型与应用程序类型模型、状态模型和任务类型模型有关系。
public function type_application()
{
return $this->belongsTo(TypeApplication::class);
}
public function type_task()
{
return $this->belongsTo(TypeTask::class);
}
public function status()
{
return $this->belongsTo(Status::class);
}
如何使用目录(type_applications、type_tasks、status_applications)制作一个通用表?
我看到了制作表格类型的解决方案。
表类型
id name title type
1 game Games type_application
2 app Application type_application
3 arcade Arcade type_application
4 create Create App type_task
5 update Update App type_task
6 publish Publish App type_task
7 created Created application status
8 moderation Moderated application status
9 publish Application published status
任务模型中将存在与类型的关系。
public function type_application()
{
return $this->belongsTo(Type::class)->whereType('type_application');
}
public function type_task()
{
return $this->belongsTo(Type::class)->whereType('type_task');
}
public function status()
{
return $this->belongsTo(Type::class)->whereType('status');
}
你能为这项任务提供更多解决方案吗?
也许某些设计模式适合这项任务?
解决方案
推荐阅读
- c# - 需要将 Int 值转换为点后有一位数的双精度值
- css - 搞砸了我的代码,试图实现 flexbox
- ruby-on-rails - 使用刺激 js 在 Rails 中渲染模态
- javascript - Node.JS V12 Trello API 如何检查卡片是否过期
- python - 使用 python PyPDF2 合并 PDF 文件
- c - 调试函数
- azure-devops - Azure DevOps REST API 执行 Git 合并
- python - 如何从多个模型 django 渲染数据
- c++ - 元素
具有无效值“多线程调试 (/MTd)” - arrays - 如何为我自己的 shell 的历史功能处理 100 的历史限制