php - 查询状态以获取未来时间的记录,查询也获取过去的记录
问题描述
我有一个查询,我试图从未来获取所有获取记录。它还获得了过去的记录。
$upcomingSupportGroups = DB::table('participants')
->join('threads', 'participants.thread_id', '=', 'threads.id')
->join('support_groups', 'threads.counselling_application_id', '=', 'support_groups.id')
->where('participants.user_id', auth()->user()->id)
->orWhere('support_groups.counsellor_id', auth()->user()->id)
->where('support_groups.event_time', '>=', Carbon\Carbon::now())
->groupBy('support_groups.id')
->get();
我哪里错了
解决方案
因为您有一个,所以orWhere('support_groups.counsellor_id', auth()->user()->id)
您可以获得顾问是身份验证用户的所有行。您要将查询更改为:
$upcomingSupportGroups = DB::table('participants')
->join('threads', 'participants.thread_id', '=', 'threads.id')
->join('support_groups', 'threads.counselling_application_id', '=', 'support_groups.id')
->where(function($query){
$query->where('participants.user_id', auth()->user()->id);
$query->orWhere('support_groups.counsellor_id', auth()->user()->id)
})
->where('support_groups.event_time', '>=', Carbon\Carbon::now())
->groupBy('support_groups.id')
->get();
推荐阅读
- javascript - React:如何仅显示使用 Array.map() 将布尔值设置为 false 的位置?
- typescript - 遍历嵌套的 JSON 子对象
- java - 如何运行java小程序
- linux - .NET Core Linux Kestrel https 配置
- c# - C# 远程 PowerShell 计算属性返回 null
- mysql - 用案例分组
- python - Python 嵌套列表(二维数组)引用
- mysql - 数据库:如何让我的购物数据库拥有各种尺寸、规格、类别、等级等的产品?
- c# - 从布局模式 MVC 5 将 SelectList 选择发送到创建视图
- c# - 自适应卡片文本无法在团队中搜索