Laravel 现有数据透视表上的多对多数据透视表
Laravel Many to Many Pivot on existing Pivot
我在 Laravel 5.1 中遇到一种情况,我想在现有关系中添加多对多关系。根据下图,我已经把所有的项目都变成绿色了。
问题是,由于 issue_person
table 上没有主键,我不知道如何向用户添加多对多关系。有谁知道我将如何完成这项工作?
所以看起来一个简单的答案就是写一个迁移,将主键添加到原始 issue_person
pivot table,然后建立多对多关系在 issue_person
和 user
之间使用 position_user
table.
我的迁移是这样的:
public function up()
{
Schema::table('issue_person', function (Blueprint $table) {
$table->increments('id');
});
}
public function down()
{
Schema::table('issue_person', function (Blueprint $table) {
$table->dropColumn('id');
});
}
我在 Laravel 5.1 中遇到一种情况,我想在现有关系中添加多对多关系。根据下图,我已经把所有的项目都变成绿色了。
问题是,由于 issue_person
table 上没有主键,我不知道如何向用户添加多对多关系。有谁知道我将如何完成这项工作?
所以看起来一个简单的答案就是写一个迁移,将主键添加到原始 issue_person
pivot table,然后建立多对多关系在 issue_person
和 user
之间使用 position_user
table.
我的迁移是这样的:
public function up()
{
Schema::table('issue_person', function (Blueprint $table) {
$table->increments('id');
});
}
public function down()
{
Schema::table('issue_person', function (Blueprint $table) {
$table->dropColumn('id');
});
}