I'm trying to extrat the number of a product which prices between 1 and the max product price using Laravel and query builder.
I tried with this query in phpmyadmin and it returns a result:
SELECT product_id , count( user_id ) , sum( monies )
FROM products, prices
WHERE monies
BETWEEN '20'
AND products.price
AND products.id = 101
GROUP BY (product_id);
But in PHP I coudn't specify the range on which we have to search :
$data = Product::join('prices', 'prices.product_id', '=', 'products.id')
->select(DB::raw('count( user_id ) as nombre'),DB::raw('sum(monies ) as sum'))
->where('prices.project_id', '=', '101')
->whereBetween('monies', array(1, 'products.price'))
->groupBy('prices.product_id')
->get();
But I always get an empty result and when I change whereBetween('monies', array(1, 'products.price')) with whereBetween('monies', array(1, 1000)) it returns a result.
How can I use the whereBetween?