拉雷维尔雄辩的框架有点麻烦。
我需要复制这样的查询:
SELECT *
FROM RepairJob
WHERE NOT EXISTS (SELECT repair_job_id
FROM DismissedRequest
WHERE RepairJob.id = DismissedRequest.repair_job_id);
现在我有
$repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')->where('active', '=', 'Y')->whereNotExists('id', [DismissedRequest::all('repair_job_id')])->get();
有人知道吗?我需要得到所有在“已驳回请求”表中没有记录的修复作业
使用上面的查询时出现此错误
Argument 1 passed to Illuminate\Database\Query\Builder::whereNotExists() must be an instance of Closure, string given
最佳答案
尝试doesnthave()方法。在repairjob模型中假设“dismissedrequests”为关系名。
$jobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
->where('active', 'Y')->doesntHave('dismissedRequests')->get();