加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

laravel Eloquent集合where方法不支持<,>,<&am

发布时间:2020-12-14 19:57:51 所属栏目:大数据 来源:网络整理
导读:今天在查询系统bug的过程中,发现laravel Eloquent集合where方法不支持,,等运算符,比如: $collection=collect([[product=Desk,price=200],[product=Chair,price=100],[product=Bookcase,price=150],[product=Door,price=100],]);$filtered=$collection-whe

今天在查询系统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方法不支持<,>,<>等运算符,所以大家需要自己更改自己的查询!


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读