1
我曾经在数据库四个表:这两张表在laravel中有什么样的关系?
- 用户(用于存储用户详情)
- 会话(用于存储会话ID)。
- conversationsmember(用于存储会话构件)
- conversationsreply(用于存储会话回复)
的用户将具有许多对话,每个对话将具有其成员和回复。
下面是详细信息:
用户迁移:
$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();
conversationsmembers迁移:
$table->increments('id');
$table->integer('conversation_id');
$table->integer('user_id');
$table->timestamps();
conversationsreply migrati ons
$table->increments('id');
$table->integer('conversation_id');
$table->integer('user_id');
$table->timestamps();
现在在用户模型中,我需要定义用户表和会话表之间的关系。由于它们不是直接相连的,我使用了ManyThrough关系。
..app /模型/ user.php的
...
public function conversations()
{
return $this->hasManyThrough('Conversation', 'ConversationsMember', 'conversation_id', 'id');
}
...
当我试图使用它,它显示一个空白阵列。