【问题标题】:Laravel advanced where not working in LumenLaravel 在 Lumen 不工作的地方进阶了
【发布时间】:2016-07-25 21:06:57
【问题描述】:

我在 Lumen 中使用 Laravel 高级 wheres 在 MongoDB 中进行查询,我在 Lumen 中使用 jenssegers/laravel-mongodb 包,我的查询是:

$time_5_min_ago = Carbon::now()->subMinute(5);
$time_10_min_ago = Carbon::now()->subMinute(10);
$time_15_min_ago = Carbon::now()->subMinute(15);

return Order::whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
    ->whereBetween('source_latitude',[$minLat_try_one,$maxLat_try_one])
    ->where('status','=','suspend')
    ->where('created_at','<=',$time_5_min_ago)
    ->where('created_at','>=',$time_10_min_ago)
    ->orWhere(function($query) use ($maxLat_try_two,$minLat_try_two,$maxLon_try_two,$minLon_try_two,$time_10_min_ago,$time_15_min_ago)
    {
        $query->whereBetween('source_longitude', [$minLon_try_two, $maxLon_try_two])
        ->whereBetween('source_latitude',[$minLat_try_two,$maxLat_try_two])
        ->where('status','=','suspend')
        ->where('created_at','<=',$time_10_min_ago)
        ->where('created_at','>=',$time_15_min_ago);
    }
    )->get();

但是当我运行这个查询时,我没有得到任何结果,我不知道如何解决它?

【问题讨论】:

  • 也许没有结果仅仅是您查询的结果?如果您没有收到错误,则代码没有任何问题。尝试逐步构建查询。
  • 但我在删除 orWhere 函数查询时得到了结果。
  • 我的意思是查询的第一部分不依赖于 orWhere 函数查询。那么为什么不显示结果
  • 请朋友们帮帮我
  • 有人知道可以帮助我

标签: php mongodb laravel lumen lumen-5.2


【解决方案1】:

我找到了解决方案。这有效:

    $time_5_min_ago = Carbon::now()->subMinute(5);
    $time_10_min_ago = Carbon::now()->subMinute(10);
    $time_15_min_ago = Carbon::now()->subMinute(15);
    $time_20_min_ago = Carbon::now()->subMinute(20);

    return Order::where(function ($query)  use ($maxLat_try_one,$minLat_try_one,$maxLon_try_one,$minLon_try_one,$time_5_min_ago,$time_10_min_ago) {
        $query->whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
            ->whereBetween('source_latitude', [$minLat_try_one,$maxLat_try_one])
            ->where('status', '=', 'pending')
            ->where('created_at', '<', $time_5_min_ago)
            ->where('created_at', '>=', $time_10_min_ago);
    })->orWhere(function ($query)  use ($maxLat_try_two,$minLat_try_two,$maxLon_try_two,$minLon_try_two,$time_10_min_ago,$time_15_min_ago) {
        $query->whereBetween('source_longitude', [$minLon_try_two, $maxLon_try_two])
            ->whereBetween('source_latitude', [$minLat_try_two,$maxLat_try_two])
            ->where('status', '=', 'pending')
            ->where('created_at', '<', $time_10_min_ago)
            ->where('created_at', '>=', $time_15_min_ago);
    })->orWhere(function ($query)  use ($maxLat_try_three,$minLat_try_three,$maxLon_try_three,$minLon_try_three,$time_15_min_ago,$time_20_min_ago) {
        $query->whereBetween('source_longitude', [$minLon_try_three, $maxLon_try_three])
            ->whereBetween('source_latitude', [$minLat_try_three,$maxLat_try_three])
            ->where('status', '=', 'pending')
            ->where('created_at', '<', $time_15_min_ago)
            ->where('created_at', '>=', $time_20_min_ago);
    })->get($fields);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-09
    • 2019-02-10
    • 2016-05-31
    • 2017-07-28
    • 2017-08-09
    相关资源
    最近更新 更多