How to write product filter query in Laravel #34402
Unanswered
imran-shabbir
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Can someone please guide me on how I can write this below query in laravel by using eloquent ORM and with QUERY Builder as well? The below code is in custom PHP, but I want to use it in laravel. I am trying to develop product filters with ajax request, filters are appearing in the sidebar when someone clicks on any filter then the system will fetch data from a database that is associated with filters, all my filters will be work as a checkbox. I don't know how I can achieve this concatenation in the laravel.
if(isset($_POST["action"]))
{
$query = "
SELECT * FROM product WHERE product_status = '1'
";
if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
{
$query .= "
AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
";
}
if(isset($_POST["brand"]))
{
$brand_filter = implode("','", $_POST["brand"]);
$query .= "
AND product_brand IN('".$brand_filter."')
";
}
if(isset($_POST["ram"]))
{
$ram_filter = implode("','", $_POST["ram"]);
$query .= "
AND product_ram IN('".$ram_filter."')
";
}
if(isset($_POST["storage"]))
{
$storage_filter = implode("','", $_POST["storage"]);
$query .= "
AND product_storage IN('".$storage_filter."')
";
}
}
Beta Was this translation helpful? Give feedback.
All reactions