title: Laravel get posts by category
body: <p>I'm trying to figure out how to get all the posts for a category using Laravel Eloquent 5.3.</p>
  
  <p>I have three tables..</p>
  
  <pre><code>**Posts**
  id | title | text
  
  **Term_relationships**
  term_id | post_id
  
  **Terms**
  id | name
  </code></pre>
  
  <p>Eloquent Models</p>
  
  <pre><code>class Term extends Model
      {
      public function posts()
      {
           return $this-&gt;belongsToMany('App\Post', 'term_relationship');
      }
  }
  
  
  class Post extends Model
  {
      public function terms()
      {
          return $this-&gt;belongsToMany('App\Term', 'term_relationship');
      }
  
  }
  
  class Term_relationship extends Model
  {
  
  }
  </code></pre>
  
  <p>I've tried with for example</p>
  
  <pre><code>Term::where('name', $category)-&gt;posts-&gt;get();
  </code></pre>