title: How do I get all of the results from a hasMany() relationship in Laravel?
body: <p>For example, I have a Product, and I have a BaseProduct.</p>
  
  <p>In the model for the Product, I've specified the following:</p>
  
  <pre><code>//In class Product
  public function BaseProduct()
  {
      return $this-&gt;belongsTo("BaseProduct", "BaseProductId");
  }
  </code></pre>
  
  <p>In the BaseProduct, I've specified the following relationship:</p>
  
  <pre><code>//In class BaseProduct
  public function Products()
  {
      return $this-&gt;hasMany("Product", "ProductId");
  }
  </code></pre>
  
  <p>If I were to select a product, like so:</p>
  
  <pre><code>$Product::first()
  </code></pre>
  
  <p>I could get the BaseProduct by doing the following:</p>
  
  <pre><code>$Product::first()-&gt;BaseProduct()-&gt;get();
  </code></pre>
  
  <p>Instead of getting the array of the result from that, how would I get the <code>Model</code> of the BaseProduct, so I can get all of the children of BaseProduct, meaning all Products that have a foreign key relating to this BaseProduct.</p>
  
  <p>I've tried <code>BaseProduct()-&gt;all();</code> instead, but it isn't a valid method.</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>I've created the following chain of function calls - but it's awful.</p>
  
  <pre><code>return BaseProduct::find(Product::first()-&gt;BaseProduct()-&gt;getResults()['BaseProductId'])-&gt;Products()-&gt;getResults();
  </code></pre>
  
  <hr>
  
  <p>Final edit:</p>
  
  <p>I had made a mistake in my <code>BaseProduct</code> model. In the <code>Products()</code> function, I had specified <code>return $this-&gt;hasMany("Product", "ProductId");</code> where <code>ProductId</code> should have been <code>BaseProductId</code>.</p>
  
  <p>After I fixed that, I could successfully use:</p>
  
  <pre><code>Product::first()-&gt;BaseProduct-&gt;products;
  </code></pre>
  
  <p>As Sheikh Heera had explained.</p>