php - OcotberCMS PivotModel $attachOne 关系
问题描述
我正在尝试many-to-many
与OcotberCMS
.
这是我的关系
public $belongsToMany = [
'users' => [
User::class,
'key' => 'task_id',
'otherKey' => 'user_id',
'table' => 'tasks_users',
'pivot' => ['status'],
'pivotModel' => TaskUser::class
]
];
在我的 pivotModel
class TaskUser extends Pivot
...
public $attachOne = [
'file' => ['System\Models\File']
];
YAML 配置
pivot:
form:
tabs:
fields:
pivot[file]:
label: Image
type: fileupload
mode: image
span: left
tab: Image
表单正确呈现,但在尝试上传文件时,抛出错误:
Upload error "A widget with class name 'relationUsersManagePivotFormPivotFile' has not been bound to the controller" on line 605 of D:\Projects\esport\modules\backend\classes\Controller.php
解决方案
似乎关系管理器无法处理很多嵌套。在枢轴模态中使用时也File
不起作用。differed binding
differed binding
不支持具有数据透视数据的关系管理器参考: https ://octobercms.com/docs/backend/relations#belongs-to-many-pivot
所以也许我们可以使用另一种方式。如果可能的话。
file
在数据透视表中,您可以添加新字段text type
- 在关系配置中指定它=>
'pivot' => ['status', 'file']
现在从外地
pivot:
form:
fields:
pivot[value]:
label: Value
type: text
pivot[file]:
label: Picture
type: mediafinder
现在您可以上传和选择文件或选择现有文件。它们将被存储,
file path
以便可以直接访问。
如有任何疑问,请发表评论。
推荐阅读
- flutter - 当我在 Android Studio 中增加 sd 卡内存时,模拟器从 AVD 管理器中删除
- html - 未显示用户名文本输入
- oauth - JavaMail oauth 需要完整的邮件范围才能通过 gmail 发送电子邮件
- mysql - Mysql/Doctrine - 检查月份是否在两个日期之间
- python - 在张量流中找到所有特征的最大值
- template-engine - 在 Jinjava 中渲染一个循环?
- java - 如何从链接列表中删除值?
- reactjs - 搜索字段的 Apollo 客户端类型策略
- sql - 将 date_diff 以天数除以 365 以获得年数
- c++ - C++ - 如果用户在我想要一个整数时输入多个字符,它会循环要求他们多次输入正确的值