Laravel 4 Laravel雄辩的ORM组在哪里

Laravel 4 Laravel雄辩的ORM组在哪里,laravel-4,eloquent,Laravel 4,Eloquent,如何将以下查询转换为Laravel4雄辩ORM select * from table where ((starttime <= ? and endtime >= ?) or (starttime <= ? and endtime >= ?) or (starttime >= ? and endtime <= ?)) 从表中选择*,其中((starttime=?)或(starttime=?)或(starttime>=?和endtime),如下所示: <

如何将以下查询转换为Laravel4雄辩ORM

select * from table where ((starttime <= ? and endtime >= ?) or (starttime <= ? and endtime >= ?) or (starttime >= ? and endtime <= ?))
从表中选择*,其中((starttime=?)或(starttime=?)或(starttime>=?和endtime),如下所示:

<?php

$results = DB::table('table')
             ->where(function($query) use ($starttime,$endtime){
                 $query->where('starttime', '<=', $starttime);
                 $query->where('endtime', '>=', $endtime);
             })
             ->orWhere(function($query) use ($otherStarttime,$otherEndtime){
                 $query->where('starttime', '<=', $otherStarttime);
                 $query->where('endtime', '>=', $otherEndtime);
             })
             ->orWhere(function($query) use ($anotherStarttime,$anotherEndtime){
                 $query->where('starttime', '>=', $anotherStarttime);
                 $query->where('endtime', '<=', $anotherEndtime);
             })
             ->get();

但是当我们使用closure时,框架会处理$query。我们如何处理$startTime和$endTime。另一方面,如果我传递类似于函数($query,$startTime){}的参数,它会抛出一个未定义的错误变量:dateRange。它会为Model:{closure}()@BishwarupDas您可以像这样将外部变量传递到闭包的范围:
$query->where(function($query)use($starttime,$endtime){…});
这里有一些示例:(特别是示例#3)选择d1.update_id from(选择update_id,将(update_id)计数为ct from updates_标记,其中标记id位于(67,33,86,55)group by update_id)作为d1,其中d1.ct=4如何将其转换为laravel查询。。。?
<?php

$results = DB::table('table')
             //this wraps the whole statement in ()
             ->where(function($query) use ($starttime,$endtime, $otherStarttime,$otherEndtime, $anotherStarttime,$anotherEndtime){

                 $query->where(function($query) use ($starttime,$endtime){
                     $query->where('starttime', '<=', $starttime);
                     $query->where('endtime', '>=', $endtime);
                 });

                 $query->orWhere(function($query) use ($otherStarttime,$otherEndtime){
                     $query->where('starttime', '<=', $otherStarttime);
                     $query->where('endtime', '>=', $otherEndtime);
                 });

                 $query->orWhere(function($query) use ($anotherStarttime,$anotherEndtime){
                     $query->where('starttime', '>=', $anotherStarttime);
                     $query->where('endtime', '<=', $anotherEndtime);
                 });
             })
             ->get();