title: How to sort through two merged collections that have different models
body: <p>I have two models <code>Cities</code> and <code>States</code>. One <code>City</code> has 1 <code>State</code> and one <code>State</code> can have 0 or more <code>Cities</code>. I need to retrieve all <code>Cities</code> and <code>States</code> separately because I need to display states even if a state has no related cities (like Alabama in the below example). The issue is I need to sort by State name first, and than by Cities in that state (if there are any) </p>
  
  <p>Cities </p>
  
  <pre><code>id, state_id, name 
  1, 1, San Diego 
  2, 1, Hollywood
  3, 2, Seattle
  4, 3, Pheonix
  </code></pre>
  
  <p>States</p>
  
  <pre><code>id, name
  1, California
  2, Washington 
  3, Arizona
  4, Alabama 
  </code></pre>
  
  <p>Controller:</p>
  
  <pre class="lang-php prettyprint-override"><code>$cities = Cities::with('state')-&gt;get(); // Returns the state relationship 
  $states = States::get();
  
  $merged = $states-&gt;merge($cities);
  </code></pre>
  
  <p>I would now like to sort by <code>State</code> name first, and then all the cities in that <code>State</code> and return a merged collection similar to this: </p>
  
  <pre class="lang-json prettyprint-override"><code>{
      id: 4,
      name: Alabama,
  }, 
  {
      id: 3,
      name: Arizona,
  }, 
  {
      id: 3,
      name: Pheonix,
      state_id: 3
      state: {
          id: 3,
          name: Arizona
      }
  },
  {
      id: 1,
      name: California
  },
  {
      id: 2,
      name: Hollywood
      state_id: 1,
      state: {
          id: 1,
          name: California
      }
  },
  {
      id: 1,
      name: San Diego,
      state_id: 1,
      state: {
          id: 1,
          name: California
      }
  }, 
  {
      id: 2,
      name: Washington,
  
  },
  {
      id: 2,
      name: Seattle,
      state_id: 2,
      state: {
          id: 2,
          name: Washington
      }
  }
  </code></pre>