Php 这两个表在laravel中将具有什么类型的关系?

Php 这两个表在laravel中将具有什么类型的关系?,php,laravel,relationship,Php,Laravel,Relationship,我在数据库中有四个表: 用于存储用户详细信息的用户 用于存储会话id的会话。 conversationsmember用于存储对话成员 会话用于存储会话回复 一个用户将有许多对话,每个对话都有其成员和回复 详情如下: 用户迁移: $table->increments('id'); $table->string('name', 32); $table->string('username', 32); $table->string('email', 320); $table-

我在数据库中有四个表:

用于存储用户详细信息的用户 用于存储会话id的会话。 conversationsmember用于存储对话成员 会话用于存储会话回复 一个用户将有许多对话,每个对话都有其成员和回复

详情如下:

用户迁移:

$table->increments('id');

$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);

$table->timestamps();
$table->increments('id');
$table->timestamps();
$table->increments('id');

$table->integer('conversation_id');
$table->integer('user_id'); 

$table->timestamps();
对话迁移:

$table->increments('id');

$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);

$table->timestamps();
$table->increments('id');
$table->timestamps();
$table->increments('id');

$table->integer('conversation_id');
$table->integer('user_id'); 

$table->timestamps();
会话成员迁移:

$table->increments('id');

$table->string('name', 32);
$table->string('username', 32);
$table->string('email', 320);
$table->string('password', 64);

$table->timestamps();
$table->increments('id');
$table->timestamps();
$table->increments('id');

$table->integer('conversation_id');
$table->integer('user_id'); 

$table->timestamps();
会话重复迁移

$table->increments('id');

$table->integer('conversation_id');
$table->integer('user_id'); 

$table->timestamps();
现在在用户模型中,我需要定义users表和conversations表之间的关系。由于它们之间没有直接的联系,所以我使用了hasManyThrough关系

…app/models/User.php

...
    public function conversations()
        {
            return $this->hasManyThrough('Conversation', 'ConversationsMember', 'conversation_id', 'id');
        }
...

当我尝试使用它时,它显示的是一个空白数组。

我会尝试一个belongTomany关系,其中conversationsmembers是您的数据透视表

public function conversations()
{
    return $this->belongsToMany('Conversation', 'conversationsmembers');
}
您可能还希望在对话模型中定义关系的倒数:

public function users()
{
    return $this->belongsToMany('User', 'conversationsmembers');
}
我对您的迁移有点困惑,所以我不确定这是您想要的