Category: PHP

Laravel PHP 多条件数据库查询

有时候搜索要用到比如select * from user where id > ? and (pid = ? or uid = ? )
可以使用如下方法:

$users = User::where('id','>','10')
->where(function($q1) use($pid,$uid){
$q1->orWhere('pid',$pid)
->orWhere('uid',$uid);
})->get();

简化一下就是这样:
$users = User::where('id','>','10')->where('enable' , 1)-get();