2017-08-05 7 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(); 

これはhelpテーブルから合計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();