Laravel 4: Where Not Exists

前端 未结 1 1000
遇见更好的自我
遇见更好的自我 2020-12-16 05:12

I need my model to return only those records from one table where a matching record does not exist in another table. I was thinking that the solution might be with Query Sco

相关标签:
1条回答
  • 2020-12-16 05:48

    Something like

    A::whereNotExists(function($query)
                {
                    $query->select(DB::raw(1))
                          ->from('B')
                          ->whereRaw('A.id = B.id');
                })
                ->get();
    
    0 讨论(0)
提交回复
热议问题