title: Laravel - Iterating pivot data (Property does not exist on this collection instance)
body: <p>I have a many-to-many relationship between <code>Order</code> and <code>Product</code></p>
  
  <p><code>Product.php</code></p>
  
  <pre><code>public function orders()
  {
      return $this-&gt;belongsToMany(Order::class)
                  -&gt;withTimestamps()
                  -&gt;withPivot('qty');
  }
  </code></pre>
  
  <p><code>Order.php</code></p>
  
  <pre><code>public function products()
  {
      return $this-&gt;belongsToMany(Product::class)
                  -&gt;withTimestamps()
                  -&gt;withPivot('qty');
  }
  </code></pre>
  
  <p>Now whenever I try to utilize an iteration in a view (in this case I am just trying to show the form which iterates through all available <code>Product</code>s, I always receive the error...</p>
  
  <pre><code>Property [products] does not exist on this collection instance.
  </code></pre>
  
  <p><code>create.blade.php</code></p>
  
  <pre><code>@foreach ($products-&gt;orders as $product)
  
  # Order inputs are here
  
  {{ Form::text('qty', $product-&gt;pivot-&gt;qty, [
                            'type' =&gt; 'tel',
                              'min' =&gt; 0,
                              'max' =&gt; 20,
                              'step' =&gt; 1,
                              'placeholder' =&gt; '0',
                              'class' =&gt; 'meal'
                              ]) }}
  @endforeach
  </code></pre>
  
  <p>I have also attempted <code>@foreach ($products-&gt;orders as $product)</code> and both approaches give me that same error. </p>
  
  <p>I have attempted many different ways in my Controller to fix this error, here is my last attempt:</p>
  
  <p><code>OrderControlller.php</code></p>
  
  <pre><code>public function create()
  {
      $user = Auth::user();
      $products = Product::get();
      $orders = $user-&gt;orders;
  
      return view('orders.create', compact('products', 'orders', 'user'));
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>@alan's answer is correct, I am sure, however...</p>
  
  <p>I am still getting "Property [pivot] does not exist on this collection instance" whenever I try to run an iteration.</p>
  
  <p>The concept of an iteration inside of an iteration in this instance is confusing for me.</p>
  
  <p>I cannot visualize how Laravel is handling the pivot connection. In tinker when I load up just the Product table, there is no <code>qty</code> column. (This makes sense because that is on the pivot table). This also explains this new error.</p>
  
  <p>Should I be doing something in the vein of this? :</p>
  
  <p>changed <code>create.blade.php</code> </p>
  
  <pre><code>@foreach ($products as $product)
   {{ Form::text('qty', $product-&gt;orders-&gt;pivot-&gt;qty }}
  </code></pre>
  
  <p>OrderController.php</p>
  
  <pre><code>$user = Auth::user();
  $orders = $user-&gt;orders;
  $products= []; #pass products to view as an array
  $p = $orders-&gt;products; #this relationship brings in pivot data? 
  foreach ($p as $orders) {
     #would I then somehow pass just this qty here?
  }
  </code></pre>
  
  <p>Problem is I am always getting a "Property does not exist" error, be it with 'products', 'orders', or 'pivot'.</p>