title: Laravel 5.5: How to get top selling items of a given shop?
body: <p>My tables are like:</p>
  
  <p><strong>shops</strong>
  <code>[id]</code></p>
  
  <p><strong>inventories</strong>
  <code>[id, shop_id]</code></p>
  
  <p><strong>orders</strong>
  <code>[id, shop_id]</code></p>
  
  <p><strong>order_item</strong>
  <code>[order_id, inventory_id, quantity]</code></p>
  
  <p>Models:</p>
  
  <pre><code>//Shop
  class Shop extends Model
  {
      public function inventories()
      {
          return $this-&gt;hasMany(Inventory::class);
      }
  
      public function orders()
      {
          return $this-&gt;hasMany(Order::class);
      }
  }
  
  //Inventory
  class Inventory extends Model
  {
      public function shop()
      {
          return $this-&gt;belongsTo(Shop::class);
      }
  
      public function orders()
      {
          return $this-&gt;belongsToMany(Order::class, 'order_items')
                      -&gt;withPivot('quantity');
      }
  }
  
  //Order
  class Order extends Model
  {
      public function shop()
      {
          return $this-&gt;belongsTo(Shop::class);
      }
  
      public function inventories()
      {
          return $this-&gt;belongsToMany(Inventory::class, 'order_items')
                      -&gt;withPivot('quantity');
      }
  }
  </code></pre>
  
  <p>Now I want 5 top selling inventories of a given shop, What will be the best possible way to do that?</p>
  
  <p>I'm on Laravel 5.5</p>