laravel - GroupBy by each month
问题描述
I'm studying GroupBy I can display year around result using below code.
How do I display each month by 'created_at'
column data?
Controller:
public function index()
{
$branches = DB::table('contacts')
->select('branch','created_at')
->orderBy('created_at')
->groupBy(DB::raw(MONTH('created_at')))
->get();
$ttl_c = Contact::count('id');
return view('index', [
'branches' => $branches,
'ttl_c' => $ttl_c,
]);
}
index.blade.php:
<table border="0">
@foreach($branches as $branches => $branch)
<tr>
<td>{{ $branch->branch }}</td>
<td>{{ $branch->branch_count }}</td>
</tr>
@endforeach
</table>
解决方案
推荐阅读
- php - MongoDB 查询与 $skip、$limit、$project 和 $lookup 上的聚合管道一起
- angular - 库之间的 Angular 6/7 循环依赖
- python - 在python中将字典转换并处理为矩阵
- c++ - 如何查看 C++ 布尔值中的数字移动?
- spring-tool-suite - 将jdk从1.8更改为10后STS不起作用
- google-analytics - 从 Google Analytics 中过滤掉幽灵流量
- c# - 为什么 C# Convert.ChangeType 不遵守指定的 Cultures NumberFormatInfo?
- spring - spring oauth 2 授权服务器应用程序与另一个应用程序共享相同的安全上下文
- python - 查找 ndarray 与 ndarray 比较的索引
- android-espresso - 测试 2 个应用程序之间的通知