Following is the SQL query that I need to perform on laravel eloquent. SQL returns expected output.
SELECT
orders.id,
orders.`status`,
order_type,
COUNT(order_type) as count
FROM
orders
WHERE
orders.`status` = 0 && order_type = 1
ORDER BY
orders.id DESC
what I have tried on laravel is below
$receved = Order::select('status', 'order_type')->where('status',0);
$relase = $receved->where('order_type', 1)->get();
$bulk = $receved->where('order_type', 2)->get();
$distiribute = $receved->where('order_type', 3)->get();
return response()->json([
'success' => true,
'message' => 'Statement Updated',
'orderStatment' => [
'relaseCount' => count($relase),
'bulkCount' => count($bulk),
'distiributeCount' => count($distiribute)
],
], 200);
I seeking recommendation/suggestion to operate this in a correct way
The output I getting on laravel is
'orderStatment' => [
'relaseCount' => 14,
'bulkCount' => 0,
'distiributeCount' => 0
],
the output of expectation and SQL produce is
'orderStatment' => [
'relaseCount' => 14,
'bulkCount' => 5,
'distiributeCount' => 4
],
There are 8 Different type of status
and 3 different types of order_type
available on Table I want to get each order_type
count of every status