【问题标题】:laravel 5.6 query builder where orWhere not workinglaravel 5.6 查询生成器在哪里或哪里不工作
【发布时间】: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 子句的位置时,会显示过去的论文,但不会显示现场论文,为什么会发生这种情况并且是他们的解决方法。

【问题讨论】:

  • 我觉得你应该考虑参数分组laravel.com/docs/master/queries#parameter-grouping
  • @prgj83 我尝试使用参数分组->orWhere(function ($query){ $query->where('papers.live_end_time','>=',$curdate); }),但我得到未定义的数据

标签: php mysql laravel-query-builder laravel-5.6


【解决方案1】:

我认为您为 orWhere 语句设置了错误的条件,请尝试使用->orWhere('papers.live_end_time', '<=' ,$curdate) 这样它将适用于您想要完成的任务

【讨论】:

  • 那没有解决问题。
猜你喜欢
  • 2017-04-17
  • 2016-07-30
  • 1970-01-01
  • 1970-01-01
  • 2013-08-21
  • 2019-11-27
  • 1970-01-01
  • 2021-06-30
相关资源
最近更新 更多