title: Laravel 5 product order relation syntax: Not unique table/alias
body: <p>I'm working on an applications which can be used to make pricelist orders for products.<br>
  <strong>In short</strong>: a restaurant has a pricelist, which they can update by following a flow where they can insert new prices.</p>
  
  <p>As result a price order will be generated. </p>
  
  <p>Now what I want is that I <strong>retrieve all categories with products</strong> (no problem) and then I want to make a <strong>relation from product to the PriceOrderProduct</strong> so I know when a product is used in an order.</p>
  
  <p>I have this now:  </p>
  
  <pre><code>ProductCategory::with('products.orderProduct')-&gt;orderBy('order')-&gt;get() 
  </code></pre>
  
  <p>which gaves me this error:   </p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 
  </code></pre>
  
  <p>complete error:  </p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'price_order_products' (SQL: select `price_order_products`.*, `price_order_products`.`product_id` as `pivot_product_id`, `price_order_products`.`id` as `pivot_id` from `price_order_products` inner join `price_order_products` on `price_order_products`.`id` = `price_order_products`.`id` where `price_order_products`.`product_id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))
  </code></pre>
  
  <p>I have searched for this error, but don't know how to fix, can someone help me out with this issue?</p>
  
  <h2>These are my tables and relations:</h2>
  
  <p>(I make use of a <code>price_</code> prefix for my tables)</p>
  
  <p><strong>Table: price_product_categories</strong><br>
  - id<br>
  category info etc. </p>
  
  <p><strong>Model: ProductCategory</strong></p>
  
  <pre><code>public function products()
  {
      return $this-&gt;hasMany(Product::class, 'product_category_id');
  }
  </code></pre>
  
  <p>==========================<br>
  <strong>price_products</strong><br>
  - id<br>
  - product_category_id<br>
  product info etc.  </p>
  
  <p><strong>Model: Product</strong></p>
  
  <pre><code>public function categories()
  {
      return $this-&gt;belongsTo(ProductCategory::class, 'product_category_id');
  }
  
  
  public function orderProduct()
  {
      return $this-&gt;belongsToMany(PriceOrderProduct::class, 'price_order_products', 'product_id', 'id');
  }
  </code></pre>
  
  <p>==========================<br>
  <strong>Table: price_orders</strong><br>
  - id<br>
  - restaurant_id<br>
  etc.  </p>
  
  <p><strong>Model: PriceOrder</strong> </p>
  
  <pre><code>public function products()
  {
      return $this-&gt;hasMany(PriceOrderProduct::class, 'order_id');
  }
  </code></pre>
  
  <p>==========================<br>
  <strong>Table price_order_products</strong><br>
  - order_id<br>
  - product_id<br>
  - price<br>
  - product_info  </p>
  
  <p><strong>Model: PriceOrderProduct</strong>  </p>
  
  <pre><code>public function orders()
  {
      return $this-&gt;belongsTo(PriceOrder::class);
  }
  
  public function products()
  {
      return $this-&gt;hasMany(Product::class, 'id', 'product_id');
  }
  </code></pre>