通过select2字段类型传递的空值

问题描述

“我的产品”模型有一个code外键,它指向一个代码模型,该模型也有一个code列,但作为主键。在“产品的CRUD的创建”视图中,我创建了一个下拉字段,该字段允许我使用Select2字段类型从所有现有的代码中进行选择。

[
    'label'     => 'Code','type'      => 'select2','name'      => 'code',// the foreign key
    'entity'    => 'productCode',// the relationship's method
    'model'     => 'App\Models\Code','attribute' => 'code',// attribute that is shown in the dropdown
]

代码在下拉列表中正确显示,但是当我保存新产品时,代码字段作为空值存储在请求中。有人知道这个问题可能是什么吗?还是我弄错了这些?

这是产品模型中的关系:

public function productCode() {
    return $this->belongsTo('App\Models\Code','code','code');
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)