Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改透视表中的字段值_Php_Laravel_Backpack For Laravel - Fatal编程技术网

Php 如何更改透视表中的字段值

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

使用Laravel双肩包,可以很容易地创建一个表单,其中包含一个字段,用于n-to-n关系

例如,背包演示项目在MonsterCrudController中显示了此配置:

'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');
我搜索了背包文档和背包演示代码,但找到了一个提示

有什么建议吗?

检查一下。