在Laravel中有日期的多个groupBy?

在Laravel中有日期的多个groupBy?,laravel,laravel-5,eloquent,Laravel,Laravel 5,Eloquent,如何实现此输出(下图) 这是我的类型表 这是我的账户表 这是我的型号 public function accounts() { return $this->hasMany('App\Accounts'); } public function type() { return $this->belongsTo('App\Type', 'type_id'); } 这是我的账户模式 public function accounts() { return $t

如何实现此输出(下图)

这是我的
类型表

这是我的
账户表

这是我的
型号

public function accounts()
{
    return $this->hasMany('App\Accounts');
}
public function type()
{
    return $this->belongsTo('App\Type', 'type_id');
}
这是我的
账户模式

public function accounts()
{
    return $this->hasMany('App\Accounts');
}
public function type()
{
    return $this->belongsTo('App\Type', 'type_id');
}
我想做的是,我想按
类型和
月份对
账户表进行分组,然后我想在每个
月份添加所有
金额
,并使用
数据表显示到表中

我尝试了这段代码,但没有给出预期的输出

$query = Accounts::with('type')->whereYear('created_at', $selectedYear)->select('type_id',
    DB::raw('type_id as type_id'), 
    DB::raw('sum(amount) as total_amount'),
    DB::raw("DATE_FORMAT(created_at,'%m') as months")
)->groupBy('months')->get();
我还是被困在这一部分


提前感谢

Laravel文档说,您可以通过groupBy方法传递多个参数


我已经做了这个groupBy类型的测试,但id不起作用,只有几个月。谢谢