0

I have Orders table and status column in my DB, the status is stored as [1,2,3,4] which is corresponding at frontend to [issued, pending, on thew ay, delivered] now I need to get the count of each status between 2 dates,

Please Note : I need the count of each status like,

issued : 80 pending : 50 on the way : 20 delivered : 170

I tried below code but don't no how to accomplish my needs

$account = DB::table('order')
                    ->whereBetween('created_at',[$fromdate, $todate])
                    ->select(DB::raw('COUNT(order.status) as total'))
                    ->get();
                    return response()->json($account,200);

Any help will be much appreciated

Mohammed Riyadh
  • 883
  • 3
  • 11
  • 34

2 Answers2

2
$account = DB::table('order')
    ->select(DB::raw('COUNT(order.id) as total'),'status')
    ->whereBetween('created_at',[$fromdate, $todate])
    ->whereIn('status',[1,2,3,4])
    ->groupBy('status')
    ->get();

return response()->json($account,200);
Tharaka Dilshan
  • 4,371
  • 3
  • 14
  • 28
0
DB::table('order')
    ->select(DB::raw('COUNT(*) as total')
    ->whereBetween('created_at',[$fromdate, $todate])
    ->groupBy('status')
    ->get();
gbalduzzi
  • 9,356
  • 28
  • 58