Here is the code for Multiple Count With Case Condition IN Mysql Laravel :
public function piechartdata()
{
$orders = Order::select(
DB::raw("
COUNT(CASE status WHEN '1' THEN 'OrderPlaced' ELSE NULL END) as OrderPlaced,
COUNT(CASE status WHEN '3' THEN 'Rejected' ELSE NULL END) as Rejected,
COUNT(CASE status WHEN '4' THEN 'Failure' ELSE NULL END) as Failure,
COUNT(CASE status WHEN '6' THEN 'Delivered' ELSE NULL END) as Delivered")
)
->where('orders.active', 1)
->orderBy('id','desc')
->get();
return response()->json(['data' => $orders], 200);
}
public function piechartdata()
{
$orders = Order::select(
DB::raw("
COUNT(CASE status WHEN '1' THEN 'OrderPlaced' ELSE NULL END) as OrderPlaced,
COUNT(CASE status WHEN '3' THEN 'Rejected' ELSE NULL END) as Rejected,
COUNT(CASE status WHEN '4' THEN 'Failure' ELSE NULL END) as Failure,
COUNT(CASE status WHEN '6' THEN 'Delivered' ELSE NULL END) as Delivered")
)
->where('orders.active', 1)
->orderBy('id','desc')
->get();
return response()->json(['data' => $orders], 200);
}
No comments:
Post a Comment