title: Get limited amount of results from related table in Laravel
body: <p>Tables</p>
  
  <pre><code>post            category
  -----           ----------
  id              id
  name            name
  category_id
  </code></pre>
  
  <p>I get limited amount of posts for each category (if category have posts)</p>
  
  <pre><code>$categories = Category::get();
  $categores_with_posts = array();
  
  foreach($categories as $category)
  {   
      $category_data = array(
          'posts' =&gt; Post::where('category_id', $category['id'])-&gt;take(10)-&gt;get()-&gt;toArray(),
          'category_id' =&gt; $category['id'],
          'name' =&gt; $category['name']
      );
  
      if(!empty($category_data['posts'])) {
          $categores_with_posts[] = $category_data;
      }
  }
  </code></pre>
  
  <p>How can i do this in Laravel using one query?</p>