我想要从我的网站购买的用户数量图表。我该如何实现?
$ordersArr = Order::where('vendor_id',$id)
->whereBetween('created_at',[$carbonStart,$carbonEnd])
->get();
我的表如下 订购
id user_id venodr_id created_at
==================================
1 1 1 2019-03-30 07:15:03
2 1 2 2019-03-30 07:20:03
3 1 1 2019-03-29 07:20:03
4 1 2 2019-03-29 07:20:03
5 2 1 2019-03-30 07:15:03
6 2 2 2019-03-30 07:20:03
7 2 1 2019-03-29 07:20:03
8 2 2 2019-03-29 07:20:03
9 2 2 2019-03-29 07:20:03
我想要的结果是
user_id count date
1 2 2019-03-30
1 2 2019-03-29
2 2 2019-03-30
2 3 2019-03-29
答案 0 :(得分:1)
$data = DB::table('order')
->select(DB::raw('user_id,count(*) as vendor_id,created_at as date'))
->whereBetween('created_at',[$carbonStart,$carbonEnd])
->groupBy('user_id')->get();