我想通过以下查询对汽车产品详细信息进行排序。但它返回一个空数组。请帮我。
public function fetchall($min_price, $max_price, $milage, $old_year, $new_year, $carbrand)
{
$cars = Cars::where([
['price','>=',$min_price],
['price','<=',$max_price],
['year','>=',$old_year],
['year','<=',$new_year],
['milage','=', $milage],
['model_id','=', $carbrand]])->get();
if (!empty($cars)) {
return $cars;
} else {
return "Check your details and submit again";
}
答案 0 :(得分:1)
而不是使用!empty($cars)
使用!$cars->isEmpty()
。
$cars
是Illuminate\Support\Collection
的对象,因此empty()
无效。
Illuminate\Support\Collection
见Available Methods。