'laravel 8 asort() expects parameter 2 to be int, string given
i want to sort and show products based on the value selected in a dropdown i.e lowest price,highest price and latest products.i have a tired the code above in the controller and in my jquery script but i get the following error asort() expects parameter 2 to be int, string given.i havent understood where i hve gone wrong with my codebase.
the function in the controller
public function merchadise (){
$products=Merchadise::where('merch_isactive',1)->paginate(2);
if(isset($_GET['nice-select'])&&!empty($_GET['nice-select'])){
if(isset($_GET['nice-select'])=="latest_products"){
$products->sortBy('id','Desc');
}elseif(isset($_GET['nice-select'])=="lowest_price"){
$products->sortBy('merch_price','Asc');
}elseif(isset($_GET['nice-select'])=="highest_price"){
$products->sortBy('merch_price','Desc');
}elseif(isset($_GET['nice-select'])=="product_name_a-z"){
$products->sortBy('merch_name','Asc');
}elseif(isset($_GET['nice-select'])=="product_name_z-a"){
$products->sortBy('merch_name','Desc');
}
}else{
$products->sortBy('id','Desc');
}
return view('frontend.product.product',compact('products'));
}
at the blade file
<div class="showing-product-number text-right">
<form name="sortproducts">
<select class="nice-select" id="nice-select">
<option value="">Default sorting</option>
<option value="latest_products">Sort by new arrivals</option>
<option value="lowest_price">Sort by price: low to high</option>
<option value="highest_price">Sort by price: high to low</option>
<option value="product_name_a-z">Product Name A-Z></option>
<option value="product_name_z-a">Product Name Z-A</option>
</select>
</form>
</div>
the script code
$(document).ready(function(){
$("#nice-select").on('change',function(){
this.form.submit();
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
