Can you show your current code that doesn't work?
Laravel price range search from multiple columns
I have to search price range(min_price & max_price) from two columns(regular_price & sale_price) but unable to get values from both columns.
$products = $products->whereBetween('ecommerce_sku.regular_price', [$minPrice, $maxPrice]);
i tried this one by adding another column in it $products = $products->whereBetween(['ecommerce_sku.regular_price','ecommerce_sku.sale_price'], [$minPrice, $maxPrice]); but didn't work for me
Then someone suggested me this one ,
$string = '(ecommerce_sku.sale_price between "'.$minPrice.'" and "'.$maxPrice.'") AND (ecommerce_sku.regular_price between "'.$minPrice.'" and "'.$maxPrice.'")'; $products = $products->whereRaw($string);
this also not work for me
Should work:
$products->whereBetween('ecommerce_sku.regular_price', [$minPrice, $maxPrice])
->orWhereBetween('ecommerce_sku.sale_price', [$minPrice, $maxPrice])
->get();
But I'm not sure what $products is in your query - is it query object, or do you have a separate EcommerceSKU Eloquent model? So it may be more complicated.
this query is not working for there. $product is object that join multiple tables to complete a product.
Please give us the whole query ( including $product) or we cannot see what is going wrong here.
$products->whereBetween('ecommerce_sku.regular_price', [$minPrice, $maxPrice]) ->orWhereBetween('ecommerce_sku.sale_price', [$minPrice, $maxPrice]) ->get();
that is the complete query. where $products have joins with multiple tables to get complete description about the Product.
That is what I am asking , give us the query of products. We want to see what is happening there.
Product::active() ->join('ecommerce_sku', 'ecommerce_sku.product_id', '=', 'ecommerce_products.id') ->where('ecommerce_sku.status', 'active') ->groupBy('ecommerce_sku.product_id', 'ecommerce_products.id');
Please or to participate in this conversation.