title: Laravel - group the record based on similar id in Laravel
body: <p>How to group the table records based on similar id in Laravel
  For Example:
  in mysql  products table  have folllowing records with similar cat id
   Table name: products</p>
  
  <pre><code>id:1 pro_name:xyz1 cat_id:55
  id:2 pro_name:xyz2 cat_id:22
  id:3 pro_name:xyz3 cat_id:55
  id:4 pro_name:xyz4 cat_id:22
  </code></pre>
  
  <p>What I am trying to do is for similar cat_id it should make its array. I Try to use</p>
  
  <pre><code>    $all = Products::groupBy('cat_id')-&gt;get();
  </code></pre>
  
  <p>But its displaying only first record of each similar cat_id.</p>
  
  <p>output I am getting:</p>
  
  <pre><code>  {
      "id": 1,
      "pro_name": "xyz1",
      "cat": "55",
      "created_at": "2017-02-09 13:09:13",
      "updated_at": "2017-02-18 11:56:04"
    },
    {
       "id": 2,
      "pro_name": "xyz2",
      "cat": "22",
      "created_at": "2017-02-22 06:04:23",
      "updated_at": "2017-02-22 06:04:23"
    }
  </code></pre>
  
  <p>I want that it should display all record of similar id in an array
  Help me for this</p>