Php Laravel雄辩的查询生成器组合

Php Laravel雄辩的查询生成器组合,php,laravel,laravel-4,eloquent,laravel-query-builder,Php,Laravel,Laravel 4,Eloquent,Laravel Query Builder,因此,我需要找到所有生产任务属于特定操作的如果 其中'status',''$monday\u date) 随着或where的实现,与操作的雄辩关系中的操作id列将被忽略 我该怎么办 以下是错误代码: return production\ProductionTask::where('operation_id', $operation->id)->where('status', '<', 3)->orWhere('expected_start', '>', $

因此,我需要找到所有
生产任务
属于
特定
操作的
如果

  • 其中
    'status',''$monday\u date)
随着
或where
的实现,与
操作的雄辩关系中的
操作id
列将被忽略

我该怎么办

以下是错误代码:

   return production\ProductionTask::where('operation_id', $operation->id)->where('status', '<', 3)->orWhere('expected_start', '>', $monday_date)->and('expected_end', '<', $sunday_date)->get();
return production\ProductionTask::where('operation_id',$operation->id)->where('status','','monday_date)->和('expected_end','p>您需要使用:

return production\ProductionTask::where('operation_id', $operation->id)
     ->where(function($q) use($monday_date) {
         $q->where('status', '<', 3)->orWhere('expected_start', '>', $monday_date);
     }->where('expected_end', '<', $sunday_date)->get();
使用前面的方法,您得到的结果如下:

SELECT * FROM production_tasks WHERE operation_id = ? AND status < 3 OR expected_start > ? AND expected_end < ?
从生产任务中选择*,其中操作id=?和状态<3或预期开始>和预期结束<?
它等于:

从生产任务中选择*,其中(操作id=?和状态<3)或(预期开始>和预期结束<?)
SELECT * FROM production_tasks WHERE operation_id = ? AND status < 3 OR expected_start > ? AND expected_end < ?
SELECT * FROM production_tasks WHERE (operation_id = ? AND status < 3) OR (expected_start > ? AND expected_end < ?)