title: create associative array from collection in laravel for checking purposes
body: <p>I am having an hard time trying to create an associative array from a collection in Laravel. The array should then be used for case checking.</p>
  
  <p>I get my collection like this:</p>
  
  <pre><code>$collected_items = $user-&gt;collected_items()-&gt;where('model_id', '=', $model_id)-&gt;get();
  </code></pre>
  
  <p>I need to extract only some relevant data from this collection like <code>'color_id'</code></p>
  
  <p>I need to check the <code>color_id</code> because I should run different code if the <code>color_id = 0, 1 or 2</code></p>
  
  <p>Since I don't want to do a DB query for every case I thought I'd better eager load the data and then put it in an associative array;</p>
  
  <p>However for the life of me I can't create this array
  I tried:</p>
  
  <pre><code>$array_of_colors = []
  
      foreach ($collected_items as $i) {
  
                      if ($i['color_id'] == 0) {
  
                          $array_of_colors += ['black' =&gt; $i-&gt;model_color_id];
                      }
                      if ($i['color_id'] == 1) {
  
                          $array_of_colors += ['colored' =&gt; $i-&gt;model_color_id];
                      }
                      if ($i['color_id'] == 2) {
  
                          $array_of_colors += ['white' =&gt; $i-&gt;model_color_id];
                      }
  
  
                  }
  </code></pre>
  
  <p>Then I would use the <code>$array_of_colors</code> to check if I have a case of black then do something, is white something else etc etc.</p>