Laravel多个地方和条件不起作用

时间:2017-11-08 09:28:33

标签: laravel

我想通过以下查询对汽车产品详细信息进行排序。但它返回一个空数组。请帮我。

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";
}

1 个答案:

答案 0 :(得分:1)

而不是使用!empty($cars)使用!$cars->isEmpty()

$carsIlluminate\Support\Collection的对象,因此empty()无效。

Illuminate\Support\CollectionAvailable Methods