-1

我在流明中有一个疑问。但它不起作用。查询是:

return Order::whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
        ->whereBetween('source_latitude',[51.365807806703,51.454384193297])
        ->where('status','=','pending')
        ->where('created_at','<=', 2016-04-07 12:00:35)
        ->where('created_at','>=', 2016-04-07 11:55:35)
        ->orWhere(function($query)
        {
                    $query->whereBetween('source_longitude', [51.321519613407, 51.498672386593])
                    ->whereBetween('source_latitude',[35.612195271526,35.756086728473])
                    ->where('status','=','pending')
                    ->where('created_at','<=',2016-04-07 11:55:35)
                    ->where('created_at','>=',2016-04-07 11:50:35);
        }
        )->get();

但是当我orWhere从查询中删除函数时,我得到了预期的结果

4

1 回答 1

1

您可能使用orWhere有点错误。您需要将 where 放到另一个 where 以正确执行查询。你现在正在做的是这样的事情where a is 1 and b is 2 or (c is 3 and d is 4),但我相信,你想做这样的事情where (a is 1 and b is 2) or (c is 3 and d is 4)
试试这个:

    return Order::where(function ($query) {
        $query->whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
            ->whereBetween('source_latitude', [51.365807806703, 51.454384193297])
            ->where('status', '=', 'pending')
            ->where('created_at', '<=', '2016-04-07 12:00:35')
            ->where('created_at', '>=', '2016-04-07 11:55:35');
    })->orWhere(function ($query) {
        $query->whereBetween('source_longitude', [51.321519613407, 51.498672386593])
            ->whereBetween('source_latitude', [35.612195271526, 35.756086728473])
            ->where('status', '=', 'pending')
            ->where('created_at', '<=', '2016-04-07 11:55:35')
            ->where('created_at', '>=', '2016-04-07 11:50:35');
    })->get();
于 2016-04-07T12:36:01.347 回答