我有一个表格Users
个,Conversations
,Messages
个,所有我需要的是获得对话列表,其中最后一条消息只属于特定用户在Laravel口才
Users
个
id | name |
---|---|
1 | User 1 |
2 | User 2 |
Conversation
个
id | name |
---|---|
1 | Conversation 1 |
2 | Conversation 2 |
3 | Conversation 3 |
Messages
个
id | user_id | conversation_id | text | created_at |
---|---|---|---|---|
1 | 1 | 1 | hi | 2022-23-12 19:33:00 |
1 | 2 | 1 | hi | 2022-23-12 19:34:00 |
1 | 2 | 2 | hello | 2022-23-12 19:35:00 |
1 | 1 | 2 | hello | 2022-23-12 19:36:00 |
我需要的是,如果我想要获得用户(ID:1)的对话列表,它只需要显示我的对话1(ID:1),因为用户1(ID:1)写了关于此对话的最后一条消息,等等...
感谢您的回复
我try 了很多东西,比如LeftJoin和WHERE条件,也try 了WHERE Exist不起作用