Laravel 多 where 并搜索

Laravel框架
397
0
0
2022-04-11
$size= (int)$request->size;
$page= (int)$request->page;
if(empty($page)) $page =1;
if(empty($size)) $size =10;
$ofsset = $size * ($page -1);
// var_dump($name);
$threatlistmodel = new ThreatList();

$total = $threatlistmodel->where(function($query) use ($data){
    $data['name'] && $query->where("name","like","%".$data['name']."%");
    isset($data['level']) && $query->where("level",$data['level']);
    isset($data['is_tb']) && $query->where("is_tb",$data['is_tb']);
    $data['end_at'] && $query->where("find_at","<=",$data['end_at'].' 23:59:59');
    $data['start_at'] && $query->where("find_at","=>",$data['start_at'].' 00:00:01');
    $query->where("is_state",1);
})->count();
//var_dump($total);
$list = $threatlistmodel->where(function($query) use ($data){
    $data['name'] && $query->where("name","like","%".$data['name']."%");
    isset($data['level']) && $query->where("level",$data['level']);
    isset($data['is_tb']) && $query->where("is_tb",$data['is_tb']);
    $data['end_at'] && $query->where("find_at","<=",$data['end_at'].' 23:59:59');
    $data['start_at'] && $query->where("find_at",">=",$data['start_at'].' 00:00:01');
    $query->where("is_state",1);
})->orderBy("id","desc")->offset($ofsset)->limit($size)->get()->each(function($item){
    $con_info = json_decode(unserialize($item->count_con),true);
    $item['ip_count'] = $con_info["total"];
    unset($item->count_con);

});