问题描述
我有这些表:
items
statistiques
item_statistique
我为items
和statistiques
创建了一个模型和AdminController。
所以我想在我的管理面板中将统计信息添加到我的商品中,没关系,但是....
在我的item_statistique
表中,我需要编辑3个字段(min
,max
和mandatory
)。
背包中有没有可以用于这种情况的字段?通常需要编辑透视字段,这一定是一种方法,但是我没有找到它:(
实际上看起来像这样:
但是不能更新每个统计信息的枢轴值:(
解决方法
在您的Item模型类中放置此关系
let array= ['shorts','tees']
let list = [];
for(let item of array) {
let obj = {};
obj[item] = [];
list.push(obj)
}
console.log(list)
在您的统计模型中放置此关系
public functions statistics(){
$this->belongsToMany(Statistic::class)->withPivot(['min','max','mandatory']);
}
然后在控制器中,您可以使用它来更新数据透视值
public functions items(){
$this->belongsToMany(Item::class)
}