WhereNotExists Laravel Eloquent

后端 未结 2 1625
灰色年华
灰色年华 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();
    
    0 讨论(0)
  • 2021-01-04 10:08

    Try doesntHave() method. Assuming 'dismissedRequests' as relation name in RepairJob model.

    $jobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
        ->where('active', 'Y')->doesntHave('dismissedRequests')->get();
    
    0 讨论(0)
提交回复
热议问题