WhereNotExists Laravel Eloquent

后端 未结 2 1650
灰色年华
灰色年华 2021-01-04 09:30

Little bit of trouble with the eloquent framework for laravel.

I need to replicate a query like this :

SELECT *
FROM RepairJob
WHERE NOT EXISTS (SE         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 10:04

    Try this:

    $repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
                  ->where('active', '=', 'Y')
                  ->whereNotExists(function($query)
                    {
                        $query->select(DB::raw(1))
                              ->from('DismissedRequest')
                              ->whereRaw('RepairJob.id = DismissedRequest.id');
                    })->get();
    

提交回复
热议问题