Laravel数据库查询返回空集合

I have a small table and try to use some filters to get some specific data out of it.

My attempt:

$matchingCars = Car::where([
    ['brand', '=', request('brand')],
    ['model', '=', request('model')],
    ['price', '<', request('maxPrice')],
])->get();

Result:

Collection {#249 ▼
  #items: []
}

You can see nothing is returned. However, if I do the queries one by one and count the result, then I get a number higher than 0, so there are models who pass my filters!

    $checkBrands = Car::where('brand', '=', request('brand'))->get(); 
    $checkModels = Car::where('model', '=', request('model'))->get(); 
    $checkPrice  = Car::where('price', '<', request('maxPrice'))->get(); 

    echo count($checkBrands) . "<br>";   //output: 1
    echo count($checkModels). "<br>";    //output: 1
    echo count($checkPrice). "<br>";     //output: 8
    die;

Why are they not stored in the collection?

You need to orWhere():-

$matchingCars = Car::where('brand', '=', request('brand'))
                   ->orwhere('model', '=', request('model'))
                   ->orwhere('price', '<', request('maxPrice'))->get()

Note:-

you said:- However, if I do the queries one by one and count the result, then I get a number higher than 0

But this doesn't mean that combination of all these three queries with AND will return result.

So apply OR condition like above.

Try this:

$matchingCars = Car::where('brand', '=', request('brand'))
    ->where('model', '=', request('model'))
    ->where('price', '<', request('maxPrice'))->get();
$matchingCars = Car::where('brand', '=', request('brand'))
                   ->where('model', '=', request('model'))
                   ->where('price', '<', request('maxPrice'))->get();

And make sure that that you have the right things returned by request()