首頁  >  問答  >  主體

使用Eloquent進行內部查詢

圖像位址包含位置和使用者總數。

Users::with(['address'=>function($query){
    $query->where('location', 'NAXAL');
    $query->order By('total');
    }])->get();

此查詢將傳回所有用戶,且查詢不符合的關係將為空。我只想提取那些在關係上不為空值的用戶,並相應地排序。

P粉056618053P粉056618053165 天前498

全部回覆(1)我來回復

  • P粉627136450

    P粉6271364502024-04-07 16:01:40

    您可以使用whereHas條件

    Users::whereHas('address', function($query){
    $query->where('location', 'NAXAL');
    $query->order By('total');
    })->get();

    回覆
    0
  • 取消回覆