【发布时间】:2018-09-08 03:43:00
【问题描述】:
我有一个页面,应该同时显示实时和过去的论文,但是当实时论文时间到期时,不应该加载实时论文,并且应该根据时间只显示过去的论文。 当前使用的查询,
$curdate=Carbon::now();
$papers = DB::table('papers')
->join('payments','papers.id','=','payments.paper_id')
->join('tutors','papers.tutor_id','tutors.id')
->select('papers.*','tutors.name')
->where('papers.id','payments.paper_id')
->where('papers.type','=','Normal')
->orWhere('papers.live_end_time', '>=' ,$curdate)
->where('payments.user_id',$id)
->get();
这显示实时文件,但不显示过去的文件。当时间到期时,实时文件将被隐藏。当我更改 where 和 orWhere 子句的位置时,会显示过去的论文,但不会显示现场论文,为什么会发生这种情况并且是他们的解决方法。
【问题讨论】:
-
@prgj83 我尝试使用参数分组
->orWhere(function ($query){ $query->where('papers.live_end_time','>=',$curdate); }),但我得到未定义的数据
标签: php mysql laravel-query-builder laravel-5.6