Here is my Orders table . How many same product are sell.
JavaScript
x
order_id product_id price
1 2 100
2 3 50
3 2 100
4 3 50
5 1 150
6 2 100
I needed
JavaScript
List product_id total_count
1 2 3
2 3 2
3 1 1
Advertisement
Answer
You can write your query n LARAVEL Eloquent in this way.
JavaScript
$response = DB::table('orders')
->select('product_id as List', DB::raw('COUNT(product_id) as total_count'), 'product_id')
->groupBy('product_id')
->get();