我正在使用多对多的关系,我想为这个属性设置两个值。
产品,
属性,
属性产品 => 产品ID、属性ID、值
我知道这不正确,但我想向您展示我的意图。
$product->attributes()->sync([
1 => [
'value' => 'sky'
],
1 => [
'value' => 'night'
],
]);
更新2
Schema::create('attribute_product', function (Blueprint $table) {
$table->unsignedInteger('product_id');
$table->unsignedInteger('attribute_id');
$table->text('value')->nullable();
$table->integer('devalue_id')->nullable(); // value id
$table->primary(['product_id', 'attribute_id', 'devalue_id']);
});
更新1
我需要设置天空和夜晚。
product_id attribute_id value devalue_id
1 1 sky 1
1 1 night 2
...