title: Sorting a Collection based on multiple criteria in Laravel
body: <p>I'm trying to sort by color first and then sort by type. </p>
  
  <p>I'm thinking maybe double foreach loops may not be the answer?</p>
  
  <p>The following is what I have so far.</p>
  
  <pre><code>private $color_order = [
      'white',
      'green',
      'purple',
      'blue',     
      ''
  ];
  
  private $type_order = [
      'diamond',
      'square',
      'circle'
  ];
  
  private function sortCards($cards, $color_order, $type_order) {
      $collection = collect($cards);
  
      return $collection-&gt;sortBy(function($card) use ($color_order, $type_order) {
          foreach ($type_order as $index =&gt; $type) {
              foreach ($color_order as $index =&gt; $color) {
                  if ($card-&gt;card_colors == $color &amp;&amp; str_contains($card-&gt;card_type, $type)) {
                      return $index;
                  }
              }
          }
      })-&gt;values();
  }
  </code></pre>