用thinkphp子查询来实现复杂的WHEREOR查询


用thinkphp子查询来实现复杂的WHEREOR查询
查找相关文章:thinkphp whereor query function

假设一个表

project_name

project_id

advertiser_id

state


查询条件 

advertiser_id=1

state=1

project_name LIKE '%$keyword%' OR project_id='$keyword'

$where = [
    'advertiser_id' => 1,
    'state' => 1,
];
$model->where($where)->where(function($query) use($keyword){
    $query->where('project_name','like','%'.$keyword.'%')
        ->whereOr('project_id',$keyword);
})->select();