今天在查询系统bug的过程中,发现laravel Eloquent集合where方法不支持<,>,<>等运算符,比如:
$collection = collect([ ['product' => 'Desk', 'price' => 200], ['product' => 'Chair', 'price' => 100], ['product' => 'Bookcase', 'price' => 150], ['product' => 'Door', 'price' => 100], ]);$filtered = $collection->where('price','<>',100);$filtered->all();
上面的算法中,你会发现会返回空数据,查看源码可以发现:
public function where($key, $value, $strict = true) { return $this->filter(function ($item) use ($key, $value, $strict) { return $strict ? data_get($item, $key) === $value : data_get($item, $key) == $value; }); }
laravel Eloquent集合where方法不支持<,>,<>等运算符,所以大家需要自己更改自己的查询!