当前位置:Gxlcms > PHP教程 > laravel5-PHP框架LaravelEloquentORMwhere多条件查询

laravel5-PHP框架LaravelEloquentORMwhere多条件查询

时间:2021-07-01 10:21:17 帮助过:57人阅读

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

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

有大神指点一下吗

回复内容:

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

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

有大神指点一下吗

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

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

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

方便一些。

多条件的话可以这样写:

$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)

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

..........

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

人气教程排行