title: Laravel Relations : Get Reviews and associated Users of a Product
body: <p>I have <strong>User</strong>, <strong>Review</strong> and <strong>Product</strong> Models in my app.<br />
  The relations are:</p>
  <blockquote>
  <ul>
  <li>User <strong>hasMany</strong> Reviews</li>
  <li>Review <strong>belongsTo</strong> User</li>
  <li>Product <strong>hasMany</strong> Reviews</li>
  <li>Review <strong>belongsTo</strong> Product</li>
  </ul>
  </blockquote>
  <p>My Table structure is</p>
  <blockquote>
  <p>Products table</p>
  <pre><code>id | name | price
  </code></pre>
  <p>Reviews Table</p>
  <pre><code>id | review | rating | user_id | product_id 
  </code></pre>
  <p>Users Table</p>
  <pre><code>id | name |   email | password
  </code></pre>
  </blockquote>
  <p>When a specific Product page is visited, I want to display all the reviews of that product along with the users who wrote these reviews. So I tried:</p>
  <pre><code>$product = Product::where('id','=',$id)-&gt;with('reviews')-&gt;with('users')-&gt;get();  
  </code></pre>
  <p>Of course that didn't work because <code>Product</code> does not have any direct relation with the <code>Users</code>.<br />
  Then I tried <a href="https://laravel.com/docs/5.3/eloquent-relationships#has-many-through" rel="nofollow noreferrer">Has Many Through</a> relation. In Product Model :</p>
  <pre><code>public function users()
  {
      return $this-&gt;hasManyThrough('App\User', 'App\Review');
  }
  </code></pre>
  <p>This requires a <code>product_id</code> column in <code>Reviews</code> table which is there.<br />
  It also expects a <code>review_id</code> column in <code>Users</code> table which is not there (and does not make sense to put it in there as a User can have many Reviews).</p>
  <h3>So what is the proper way of doing this ?</h3>
  <p>How do I get all the reviews of a specific Product along with the users who wrote those reviews ?</p>