Laravel仅按日期和月份分组并获得计数 [英] Laravel group by date to month only and get count
本文介绍了Laravel仅按日期和月份分组并获得计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有交易表:
我的表架构:
id | item_name | quantity | created_at
我尝试了很多方法,但是没有用(链接: Laravel Eloquent get结果按天分组.
I have try many method but its not work (link : Laravel Eloquent get results grouped by days.
我想这样显示它:
示例:
数量:xxx 月:七月
Qty : xxx Month : July
数量:xxx 月:十月
Qty : xxx Month : October
数量:xxx 月:11月
Qty : xxx Month : November
如何将created_at列转换为仅按月分组,并显示为Word(而不是数字),然后获得该月的分组数量计数?
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?
谢谢
推荐答案
$data= Transaction::select('id', 'item_name','quantity', 'created_at')
->get()
->groupBy(function($val) {
return Carbon::parse($val->created_at)->format('m');
});
这篇关于Laravel仅按日期和月份分组并获得计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文