Laravel Backpack添加/更新数据透视表值

问题描述

我有这些表:

items

statistiques

item_statistique

我为itemsstatistiques创建了一个模型和AdminController。 所以我想在我的管理面板中将统计信息添加到我的商品中,没关系,但是....

在我的item_statistique表中,我需要编辑3个字段(minmaxmandatory)。 背包中有没有可以用于这种情况的字段?通常需要编辑透视字段,这一定是一种方法,但是我没有找到它:(

实际上看起来像这样:

enter image description here

但是不能更新每个统计信息的枢轴值:(

解决方法

在您的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)
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...