本文介紹了WhereNotExists Laravel Eloquent的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
laravel 的雄辯框架有點小麻煩.
Little bit of trouble with the eloquent framework for laravel.
我需要復制這樣的查詢:
I need to replicate a query like this :
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();
有人有什么想法嗎?我需要獲取在已駁回請求表中沒有記錄的所有維修作業
Anyone an idea? I need to get all the repairjobs where there is no record for in the dismissed requests table
使用上述查詢時出現此錯誤
I get this error when using the query above
Argument 1 passed to IlluminateDatabaseQueryBuilder::whereNotExists() must be an instance of Closure, string given
推薦答案
嘗試 dontHave() 方法.假設dismissedRequests"作為 RepairJob 模型中的關系名稱.
Try doesntHave() method. Assuming 'dismissedRequests' as relation name in RepairJob model.
$jobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
->where('active', 'Y')->doesntHave('dismissedRequests')->get();
這篇關于WhereNotExists Laravel Eloquent的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!