圖像位址包含位置和使用者總數(shù)。
Users::with(['address'=>function($query){ $query->where('location', 'NAXAL'); $query->order By('total'); }])->get();
此查詢將傳回所有用戶,且查詢不符合的關(guān)係將為空。我只想提取那些在關(guān)係上不為空值的用戶,並相應(yīng)地排序。
您可以使用whereHas條件
Users::whereHas('address', function($query){ $query->where('location', 'NAXAL'); $query->order By('total'); })->get();