在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不起作用,只有几个月。谢谢