Laravel UNION ALL不使用where语句

时间:2015-09-29 15:40:42

标签: php laravel where laravel-5.1 union-all

我希望将两个队列合二为一。

$buildings_queue=IngameBuildingQueue::where(DB::raw('UNIX_TIMESTAMP(`start_time` + `duration`)'),'<=',time());
$recruit_queue=IngameRecruitQueue::where(DB::raw('UNIX_TIMESTAMP(`start_time` + `duration`)'),'<=',time());
$queue=$buildings_queue->unionAll($recruit_queue);
dd($queue->toSql());

Laravel throw:

  

[ErrorException]未定义的属性:Illuminate \ Database \ Eloquent \ Builder :: $ bindings

但是当我删除where()方法时,一切正常。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

根据Laravel用户手册,这应该可行

IngameRecruitQueue::where(DB::raw('UNIX_TIMESTAMP(`start_time` + `duration`)'),'<=',time())->union($buildings_queue)->get();

还尝试在camelCase约定中编写变量

$ buildings_queue $ buildingsQueue

查看此答案以了解详情:https://softwareengineering.stackexchange.com/a/196463