Php 如何更改透视表中的字段值
使用Laravel双肩包,可以很容易地创建一个表单,其中包含一个字段,用于n-to-n关系 例如,背包演示项目在MonsterCrudController中显示了此配置:Php 如何更改透视表中的字段值,php,laravel,backpack-for-laravel,Php,Laravel,Backpack For Laravel,使用Laravel双肩包,可以很容易地创建一个表单,其中包含一个字段,用于n-to-n关系 例如,背包演示项目在MonsterCrudController中显示了此配置: 'label' => 'Relationship (also uses InlineCreate; Fetch using AJAX), 'type' => 'relationship', 'name' => 'products', 'entity' => 'produ
'label' => 'Relationship (also uses InlineCreate; Fetch using AJAX),
'type' => 'relationship',
'name' => 'products',
'entity' => 'products',
// 'attribute' => 'name',
'tab' => 'Relationships',
Monster模型显示了关系是如何构建的:
public function products()
{
return $this->belongsToMany(\App\Models\Product::class, 'monster_product');
}
迁移显示创建透视表中的字段:
Schema::create('monster_product', function (Blueprint $table) {
$table->increments('id');
$table->integer('monster_id')->unsigned();
$table->integer('product_id')->unsigned();
$table->string('notes');
$table->nullableTimestamps();
$table->softDeletes();
});
我试图找出如何为透视表中的notes
字段设置值
如何声明模型的额外属性:
return $this->belongsToMany(Role::class)->withPivot('active', 'created_by');
我搜索了背包文档和背包演示代码,但找到了一个提示
有什么建议吗?检查一下。