【问题标题】:Laravel Many to Many Pivot on existing PivotLaravel 现有 Pivot 上的多对多 Pivot
【发布时间】:2015-12-23 11:53:51
【问题描述】:

我在 Laravel 5.1 中有一种情况,我想在现有关系中添加多对多关系。根据下图,我已经把所有绿色的项目都搞定了。

问题是由于issue_person 表上没有主键,我不知道如何向用户添加多对多关系。有谁知道我将如何做到这一点?

【问题讨论】:

    标签: php laravel many-to-many relationship


    【解决方案1】:

    因此,一个简单的答案似乎是编写一个迁移,将主键添加到原始issue_person 数据透视表,然后在issue_personuser 之间建立多对多关系使用position_user 表。

    我的迁移如下所示:

    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');
        });
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 2021-10-02
      • 2021-01-13
      • 1970-01-01
      • 2014-02-10
      • 2019-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多