title: Eloquent grouping of arrays - Laravel
body: <p>I have my models and relationships setup correctly in <code>laravel</code> and I can retrieve data using the code below;</p>
  
  <pre><code>$restaurants = Restaurant::with('restaurantClass', 'city', 'location', 'menuCategories', 'menuItems', 'menuModifierGroups', 'menuModifierItems')-&gt;where(['id' =&gt; $id])-&gt;get();
  </code></pre>
  
  <p><code>restaurant</code> belongs to <code>'restaurantClass', 'city', 'location'</code></p>
  
  <p><code>restaurant</code> has many <code>'menuCategories', 'menuItems', 'menuModifierGroups', 'menuModifierItems'</code></p>
  
  <p>I get my <code>data</code> like below;</p>
  
  <pre><code>[
    {
      // restaurant details here,
      "restaurant_class": {},
      "city": {},
      "location": {},
      "menu_categories": [],
      "menu_items": [],
      "menu_modifier_groups": [],
      "menu_modifier_items": []
    }
  ]
  </code></pre>
  
  <p><code>menu_categories</code> has many <code>'menuItems', 'menuModifierGroups', 'menuModifierItems'</code></p>
  
  <p>How can I group them by <code>menu_categories</code>?
  So basically group the inner arrays.</p>