title: Grouping morphed models by model type after mapToGroups()
body: <p>When featuring content on my application, I need to handle different types of content models like <code>Music</code> and <code>Author</code>. To do this, I have a Feature model and FeaturableTrait (containing the <code>morphTo()</code> relation which I added to the Featurable models.</p>
  
  <p>My feature model looks like this:</p>
  
  <pre><code>class Feature extends BaseModel
  {
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = ['name', 'featurable_id', 'featurable_type'];
  
      /**
       * Get all of the owning featurable models.
       */
      public function featurable()
      {
          return $this-&gt;morphTo();
      }
  }
  </code></pre>
  
  <p>To complicate things a little further, I have different sub-sections within my featured section like "Spotlight", "Editor's Choice", "Trending" etc.</p>
  
  <p>In my <code>FeatureController</code>, I need to pull all the records from the <code>features</code> table, map them to groups based on the <code>name</code> attribute, then group the resulting groups again by <code>featurable_type</code> so that the app can distinguish them in the UI.</p>
  
  <p>So far, I've done:</p>
  
  <pre><code>// Get the records from the database and eager load the featurable model
  
  $features = Feature::with(['featurable'])
      -&gt;orderBy('name')
      -&gt;orderBy('featurable_type')
      -&gt;get();
  
  // Separate into collection groups based on the feature sub-section
  $features = $features-&gt;mapToGroups(function ($item, $key) {
      return [$item['name'] =&gt; $item['featurable']];
  });
  
  // Do something to separate the featurable models in each subsection by model type
  
  // Return the result
      return $features;
  </code></pre>
  
  <p>I want the result to have a collection of featured sections, which inside them have a separate collection for each <code>featurable_type</code> differentiating between the <code>Music</code> and <code>Artist</code> models so that I can send each model to it's appropriate transformer.</p>
  
  <p>Been stuck on this for a day and a half now, so if anyone can give me some inspiration with collection kung-fu, I'd really appreciate it.</p>