public function ReportAccurate($data)
{
if(is_array($data))
{
$where = $this->whereAll($data);
return $where;
}
else
{
return false;
}
}
/*多条件模糊*/
public function whereAll($data)
{
$query = new ReportMainpage();
$results = $query->where(function ($query) use ($data) {
$data['report_first_received_date'] && $query->where('report_first_received_date', 'like', '%' . $data['report_first_received_date'] . '%');
$data['report_drug_safety_date'] && $query->where('report_drug_safety_date', 'like', '%' . $data['report_drug_safety_date'] . '%');
$data['aecountry_id'] && $query->where('aecountry_id', $data['aecountry_id']);
$data['received_fromid_id'] && $query->where('received_fromid_id', $data['received_fromid_id']);
$data['research_id'] && $query->where('research_id', 'like', '%' . $data['research_id'] . '%');
$data['center_number'] && $query->where('center_number', 'like', '%' . $data['center_number'] . '%');
})->get();
return $results;
}
上面的$data为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素
不好的地方 代码不健壮 不利于维护