2017-08-05 35 views
1

這是我的查詢。設置限制爲雄辯關係

$helpCategoryList = HelpCategory::where('is_active', 1) 
           ->with(['helps' => function($query) { 
      $query->with(['users']) 
        ->withcount(['helpComments','helpResponse','helpVotes']) 
        ->limit(5);}]) 
      ->orderBy('created_at', 'asc') 
      ->get() 
      ->toArray(); 

它從幫助表中給出了5條記錄,但我需要每個類別5條記錄的幫助細節。 所以每個類別都有很多幫助。

回答

2

這是有點晚了,但我嘗試解一次,我希望它會工作

$helpCategoryList = HelpCategory::where('is_active', 1) 
          ->with('helps')->whereHas('helps',function($query) { 
            $query->with(['users']) 
            ->withcount(['helpComments','helpResponse','helpVotes']) 
             ->take(5);}) 
          ->orderBy('created_at', 'asc') 
          ->get() 
          ->toArray();