美文网首页
LARAVEL 按照时段统计今天、7天、30天的数据(统计图)

LARAVEL 按照时段统计今天、7天、30天的数据(统计图)

作者: 大萝卜2022 | 来源:发表于2022-08-25 17:52 被阅读0次

    [laravel数据统计绘图(今天、7天、30天数据)]

    $time = 7;
    $data_arr = Info::where('created_at','<', Carbon::now())
                    ->where('created_at','>', $time > 1 ? Carbon::today()->subDays($time):Carbon::today())
                    ->select([$time > 1 ? DB::raw('DATE(created_at) as time') : DB::raw('DATE_FORMAT(created_at,\'%H\') as time'), DB::raw('COUNT("*") as count')])
                    ->groupBy('time')
                    ->get();
    

    相关文章

      网友评论

          本文标题:LARAVEL 按照时段统计今天、7天、30天的数据(统计图)

          本文链接:https://www.haomeiwen.com/subject/wgxxnrtx.html