title: Laravel 9 add new key and values using crossJoin collection
body: <p>so i have a table <strong>Items</strong> my table has a row <em><code>product</code></em> and <code>price</code> only. my goal is how to
  add key with values using crossJoin collect</p>
  <p>here is my code when fetching all data in my table im using <code>each</code> collect to add new row with values</p>
  <pre><code>public function ProductList(){
      $items = Item::all(); //rows only 'product', 'price'
      $Brand = collect($items)-&gt;each(function($newRow){
          $newRow-&gt;color = 'Blue'; // adding this in row
          $newRow-&gt;size = 'Large'; // adding this in row
      });
      return $Brand ;
  }
  </code></pre>
  <p>here is the output of that code</p>
  <pre><code>[
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  }
  ]
  </code></pre>
  <p>in the output <code>color</code> and <code>size</code> has been added to key with the values of <code>blue</code> and <code>large</code>.
  but that it's not the output i want to show. i want is each items color have a BLUE , BLACK , WHITE and size LARGE , MEDIUM , SMALL</p>
  <p>like this code: ( i will not include the price )</p>
  <pre><code>   public function test(){
          $item = ['Lee','Jeans','Guess','Levis'];
          $size = ['LARGE','MEDIUN','SMALL'];
          $color = ['BLUE','BLACK','WHITE'];
          return collect($item)-&gt;crossJoin($size,$color);
      }
  </code></pre>
  <p>the output of this</p>
  <pre><code>  [
      [
      &quot;Lee&quot;,
      &quot;LARGE&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;LARGE&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;LARGE&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;MEDIUN&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;SMALL&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;SMALL&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Lee&quot;,
      &quot;SMALL&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;LARGE&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;LARGE&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;LARGE&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;MEDIUN&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;SMALL&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;SMALL&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Jeans&quot;,
      &quot;SMALL&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;LARGE&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;LARGE&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;LARGE&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;MEDIUN&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;SMALL&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;SMALL&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Guess&quot;,
      &quot;SMALL&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;LARGE&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;LARGE&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;LARGE&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;MEDIUN&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;MEDIUN&quot;,
      &quot;WHITE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;SMALL&quot;,
      &quot;BLUE&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;SMALL&quot;,
      &quot;BLACK&quot;
      ],
      [
      &quot;Levis&quot;,
      &quot;SMALL&quot;,
      &quot;WHITE&quot;
      ]
    ]
  </code></pre>
  <p>so i tried this code but the output i want is not like this.</p>
  <pre><code>  public function ProductList(){
          $items = Item::all(); //rows only 'product', 'price'
          $statusBrand = collect($items)-&gt;each(function($newRow){
              $newRow-&gt;color = 'Blue'; // adding this in row
              $newRow-&gt;size = 'Large'; // adding this in row
          })-&gt;crossJoin(['BLUE','WHITE','LARGE'],['LARGE','MEDIUM','SMALL']);
          return $statusBrand;
      }
  </code></pre>
  <p>output of this:</p>
  <pre><code>[
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 1,
  &quot;product&quot;: &quot;Lee&quot;,
  &quot;price&quot;: &quot;500&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 2,
  &quot;product&quot;: &quot;Jeans&quot;,
  &quot;price&quot;: &quot;400&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 3,
  &quot;product&quot;: &quot;Guess&quot;,
  &quot;price&quot;: &quot;300&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;BLUE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;WHITE&quot;,
  &quot;SMALL&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;LARGE&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;MEDIUM&quot;
  ],
  [
  {
  &quot;id&quot;: 4,
  &quot;product&quot;: &quot;Levis&quot;,
  &quot;price&quot;: &quot;200&quot;,
  &quot;color&quot;: &quot;Blue&quot;,
  &quot;size&quot;: &quot;Large&quot;
  },
  &quot;LARGE&quot;,
  &quot;SMALL&quot;
  ]
  ]
  </code></pre>
  <p>in that code the crossJoin data entries has been added outside of the data array
  the output i want to show is the <code>color</code> and <code>size</code> will be add in the data each of them</p>