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
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
What I am trying to do is for similar cat_id it should make its array. I Try to use
$all = Products::groupBy('cat_id')->get();
But its displaying only first record of each similar cat_id.
output I am getting:
{
"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"
}
I want that it should display all record of similar id in an array Help me for this