澳门品牌集成灶设计-华图命中2019湖南省考常识真题

首页

AD联系:507867812

澳门品牌集成灶设计

时间:2019-11-18 08:40:29 作者:大发888登录下载 浏览量:39930

澳门品牌集成灶设计Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法,见下图

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

,见下图

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

,如下图

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

如下图

Laravel5中实现模糊匹配加多条件查询功能的方法,如下图

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

,见图

澳门品牌集成灶设计

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

澳门品牌集成灶设计

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法。

Laravel5中实现模糊匹配加多条件查询功能的方法

1.Laravel5中实现模糊匹配加多条件查询功能的方法

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

2.

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

3.

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

4.

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

Laravel5中实现模糊匹配加多条件查询功能的方法Laravel5中实现模糊匹配加多条件查询功能的方法

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

。澳门品牌集成灶设计

展开全文
相关文章
bet.pdf?game_id=

Laravel5中实现模糊匹配加多条件查询功能的方法

ceo娱乐多少年了

Laravel5中实现模糊匹配加多条件查询功能的方法....

下载澳门龙虎和新版

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

通博老虎机游戏下载大全

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

怎么看庄闲大小路_真人登陆开户

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

相关资讯
yy棋牌怎么改名字 read.php

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

菲律宾招聘信息网 企业 邮箱

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

澳门儿童3d打印机企业

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

电子送彩金平台

本文实例讲述了Laravel5中实现模糊匹配加多条件查询功能的方法。分享给大家供大家参考,具体如下:

方法1. ORM模式

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为前端传过来的数组 利用封装拼接进行模糊或者精确的多条件搜素

不好的地方 代码不健壮 不利于维护

方法2. 大神封装法 利用到的知识是Repository 仓库

$fields = ['id', 'report_id', 'report_identify', 'report_first_received_date', 'drug_name', 'first_event_term', 'case_serious', 'standard_of_seriousness', 'case_causality', 'received_from_id', 'task_user_name', 'organize_role_name', 'task_countdown', 'report_countdown'];/*查询的字段*/$searchFields = [ 'report_identify' => 'like', 'drug_name' => 'like', 'event_term' => 'like', 'organize_role_id' => '=', 'case_causality' => '=', 'report_type' => '=', 'task_user_id' => '=', 'status' => '=',];/*获取查询条件*/$where = $this->searchArray($searchFields);/*获取数据*/$this->reportTaskRepo->pushCriteria(new OrderBySortCriteria('asc', 'task_countdown'));$data = $this->reportTaskRepo->findWhere($where, $fields);//在Trait里封装/** * 获取请求中的参数的值 * @param array $fields [description] * @return [type] [description] */public function searchArray($fields=[]){ $results = []; if (is_array($fields)) { foreach($fields as $field => $operator) { if(request()->has($field) && $value = $this->checkParam($field, '', false)) { $results[$field] = [$field, $operator, "%{$value}%"]; } } } return $results;}

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

....

热门资讯