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

2

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is what i was looking for
0
DB::table('order')
    ->select(DB::raw('COUNT(*) as total')
    ->whereBetween('created_at',[$fromdate, $todate])
    ->groupBy('status')
    ->get();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.