Group by in laravel Eloquent

in this simple article eloquently of group by query in laravel eloquent. We will use laravel group by query. Yes If you more than Same Raw Same Like Word or Int value Group by in laravel Eloquent .

model to have an additional field named `confluence_version` to display all versions. To do that, add new model migration file named project.migration with the below content Group by in laravel Eloquent .

So response are particular once realize yea i help succesfully.

Example 1:

Group by in laravel Eloquent
select * from `tbl_man` group by `status`

Example 2:

 public function index()    {    
  
  $tbl_man = tbl_man::get();     
    
 dd($tbl_man);  

  }

Example 3:

Response:

{
"status":1,
"message":"Product List Successfully",
"data":[
     {
        "category_id":16,
        "is_parent_of":0,
        "created_at":"2021-01-09 10:52:35",
        "category_name":"Electronics",
        "image_url":"public/uploads/9.png",
        "created_at":"2021-01-09 10:52:35"
     },
     {
        "category_id":17,
        "is_parent_of":0,
        "category_name":"Fashion",
        "image_url":"public/uploads/10.png",
        "created_at":"2021-01-09 11:17:47"
     },
     {
        "category_id":18,
        "is_parent_of":0,
        "category_name":"Furniture",
        "image_url":"public/uploads/11.png",
        "created_at":"2021-01-09 11:18:25"
     },
     {
        "category_id":16,
        "is_parent_of":0,
        "created_at":"2021-01-09 10:52:35",
        "category_name":"Electronics",
        "image_url":"public/uploads/12.png",
        "created_at":"2021-01-09 10:52:35"
     },
     {
        "category_id":84,
        "is_parent_of":0,
        "category_name":"Properties",
        "image_url":"public/uploads/13.png",
        "created_at":"2021-03-23 05:37:13"
     }
]

Example 4:

“category_name”:”Electronics, ->And in this response given by use GroupBy any one column and remove same name automatically Group by in laravel Eloquent….

 public function index()    {    
  
  $tbl_man = tbl_man::groupBy('category_name')->get();     
    
 dd($tbl_man);  

  }

Example 5:

{
"status":1,
"message":"Product List Successfully",
"data":[
     {
        "category_id":16,
        "is_parent_of":0,
        "created_at":"2021-01-09 10:52:35",
        "category_name":"Electronics",
        "image_url":"public/uploads/9.png",
        "created_at":"2021-01-09 10:52:35"
     },
     {
        "category_id":17,
        "is_parent_of":0,
        "category_name":"Fashion",
        "image_url":"public/uploads/10.png",
        "created_at":"2021-01-09 11:17:47"
     },
     {
        "category_id":18,
        "is_parent_of":0,
        "category_name":"Furniture",
        "image_url":"public/uploads/11.png",
        "created_at":"2021-01-09 11:18:25"
     },
     {
        "category_id":84,
        "is_parent_of":0,
        "category_name":"Properties",
        "image_url":"public/uploads/13.png",
        "created_at":"2021-03-23 05:37:13"
     }
]

And i hope this blog post is helpful..

Leave a Comment