php – 查询私人聊天参与者查询
发布时间:2020-12-13 22:26:03 所属栏目:PHP教程 来源:网络整理
导读:我创建了一个私人聊天 我的数据库看起来像这样 +----+--------------------------------------+---------+------------------+---------------------+---------------------+| id | msg | user_id | receiver_user_id | created_at | updated_at |+----+----
我创建了一个私人聊天
我的数据库看起来像这样 +----+--------------------------------------+---------+------------------+---------------------+---------------------+ | id | msg | user_id | receiver_user_id | created_at | updated_at | +----+--------------------------------------+---------+------------------+---------------------+---------------------+ | 1 | In dui magna posuere | 1 | 2 | 2016-03-27 11:50:25 | 0000-00-00 00:00:00 | | 2 | Sed a libero | 1 | 2 | 2016-03-27 11:50:41 | 0000-00-00 00:00:00 | | 3 | Vivamus consectetuer hendrerit lacus | 3 | 1 | 2016-03-27 11:51:09 | 0000-00-00 00:00:00 | | 4 | Aenean leo ligula | 4 | 1 | 2016-03-27 16:13:32 | 0000-00-00 00:00:00 | +----+--------------------------------------+---------+------------------+---------------------+---------------------+ 我正在尝试获取聊天参与者的列表, 因此,如果我是用户ID 1,我的参与者是2,3,4 如果我是用户ID 4,我的参与者是1 我不知道该怎么做. 解决方法$users = PM::select('user_id') ->where('receiver_user_id','=',Auth::user()->id) ->union(PM::select('receiver_user_id')->where('user_id',Auth::user()->id)); 将其添加到答案中,以便它不会显示在未回答的问题中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |