I'm trying to convert my sql query to Laravel Query From this
SELECT products.name,
(SELECT SUM(orders.date BETWEEN from_date AND to_date)
FROM orders WHERE orders.product_id = products.id ) as order_counts
FROM products;
Then I tried converting to laravel query builder but it results to an error:
Product::select('name',
DB::raw("SUM(orders.date
BETWEEN $request->from_date AND $request->to_date) AS total_orders
FROM orders WHERE orders.product_id = products.id"))
->get();
The error is syntax error on the $request->from_date inside db::raw.