I am working on a page with two separate ajax calls (using Laravel). The first call triggers the second one, but the options for the second ajax are in a select box. Here is my current solution:
public function getCategoryAjax(Request $request)
{
$product = Product::where('category_id',$request->get('category_id'))->get();
return $product;
}
public function getPriceAjax(Request $request)
{
$withPrice = Product::where('category_id',$request->get('category_id'));
if ($request->get('price') == 1){
$withPrice=$withPrice->where('min_price','<', 1000000)->get();
}elseif ($request->get('price') == 2){
$withPrice=$withPrice->where('min_price','>', 1000000)->andWhere('max_price','<',2000000)->get();
}
return $withPrice;
}
The first method handles the first ajax call, while the second method uses an if-else statement to handle the options from the select box.
My question is, is there a more efficient way to accomplish this? https://i.sstatic.net/3PN8t.png (The select box on the left is used for the second ajax call)