查询状态以获取未来时间的记录,查询还获取过去的记录

时间:2018-11-19 17:16:06

标签: php laravel

我有一个查询,试图在将来获取所有获取记录。它也从过去获取记录。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css">

<div class="row" data-bind="foreach: MHxReport">
  <div style="margin:12px 0 12px 0;">
    <div class="col-sm-12 col-md-12 col-lg-12">
      <div class="table-responsive dsg-btm-shadow" data-bind="foreach: ColumnList">
        <span data-bind="text: 'table '+$index()"></span>
        <table class="dsg-setup dsg-aligntop table" style="padding:10px" border="0">
          <tbody data-bind="foreach: $data">
            <tr data-bind="foreach: { data: Object.keys($data), as: 'key' }">
              <td><span data-bind='text: $parent[key]'></span></td>
            </tr>
          </tbody>
        </table>
        <br> <br>
      </div>
    </div>
  </div>
</div>

我要去哪里了

1 个答案:

答案 0 :(得分:2)

因为您有一个orWhere('support_groups.counsellor_id', auth()->user()->id),所以您得到的所有行中顾问都是auth用户。您要将查询更改为:

$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();