Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel group by date to month only and get count

Tags:

laravel-5

I have transactions table :

My table architecture :

id | item_name | quantity | created_at

I have try many method but its not work (link : Laravel Eloquent get results grouped by days.

I want to display it like this :

Example :

Qty : xxx Month : July

Qty : xxx Month : October

Qty : xxx Month : November

How to convert from created_at column to month only grouping and display it as Word instead of numbers and then get count of grouping quantity in that month?

Thank you

like image 383
Muhammad Mu'az Avatar asked Dec 05 '22 02:12

Muhammad Mu'az


1 Answers

    $data= Transaction::select('id', 'item_name','quantity', 'created_at')
            ->get()
            ->groupBy(function($val) {
            return Carbon::parse($val->created_at)->format('m');
     });
like image 81
Anns Rahim Avatar answered Feb 04 '23 04:02

Anns Rahim