首页 > PHP框架 Laravel Eloquent ORM where 多条件查询

PHP框架 Laravel Eloquent ORM where 多条件查询

 $goodsShow = Goods::where('product_id','=',$id)->first();

这个是 查询一个条件呢 我想在where 里面 在增加 几个条件 可以吗

有大神指点一下吗


多条可以使用苏生不惑的方法
其实单个条件可以写成

$goodsShow = Goods::where('product_id', $id)->first();

方便一些。


$goodsShow = Goods::where([product_id'=>$id,'name'=>$name])->first();


感觉laravel是不是 仿thinkphp的。
还有个问题就是 如果我想写多个 带自定义逻辑符号的 我觉得 @JefferyWang 这个方法还是不错的


可以传递数组嘛,就像thinkphp一样的


多条件的话可以这样写:

$goodsShow = Goods::where('cate_id','=',$cate_id)
    ->where(function($query){
        $query->where('status','<','61')
            ->orWhere(function($query){
                $query->where('status', '91');
            });
    })->first();

这一段其实执行的就是where cate_id = $cate_id AND (status < 61 OR status = 91)


..........

【热门文章】
【热门文章】