PHP基于一个文本值过滤器查询所有列

伊扎特

我正在尝试创建一个文本字段过滤器,该过滤器的值可以从表的所有列中查询所有具有过滤器值的数据。现在我现有的代码只能从users.name下面的列中查询,这是我当前的代码:

$employeeDetails = DB::table('employees')
                            ->join('users', 'users.id', '=', 'employees.user_id')
                            ->leftjoin('cost_centres', 'cost_centres.id', '=', 'employees.cost_centre_id')
                            ->leftjoin('departments', 'departments.id', '=', 'employees.department_id')
                            ->leftjoin('sections', 'sections.id', '=', 'employees.section_id')
                            ->leftjoin('employee_positions', 'employee_positions.id', '=', 'employees.position_id')
                            ->leftjoin('teams', 'teams.id', '=', 'employees.team_id')
                            ->leftjoin('categories', 'categories.id', '=', 'employees.category_id')
                            ->leftjoin('branches', 'branches.id', '=', 'employees.branch_id')
                            ->leftjoin('areas', 'areas.id', '=', 'employees.area_id')
                            ->leftjoin('employee_grades', 'employee_grades.id', '=', 'employees.grade_id')
                            ->leftjoin('attendance_group_area','attendance_group_area.area_id','employees.area_id')
                            ->whereIn('employees.id', $leaveTransactionEmployees)
                            ->where('users.name', 'LIKE', '%'.$filterValue.'%')
                            ->select('employees.*','users.name as name', 'cost_centres.name as costCentre', 'departments.name as department', 'sections.name as section',
                                'employee_positions.name as position', 'teams.name as team', 'areas.name as area', 'employee_grades.name as grade',
                                'categories.name as category', 'attendance_group_area.attendance_group_id as attendance_group_id')
                            ->get();
        return response()->json($employeeDetails);

如您所见,我现在拥有的唯一过滤器是这个,并且它是1列的唯一过滤器

->where('users.name', 'LIKE', '%'.$filterValue.'%')

如果该值存在于我的任何列中,那么我该如何使用相同的值来过滤所有我左连接的表中的所有列。

卡罗尔·索本斯基

只需使用orWhere

$collection->where('sth', '=', '%'.$xxxx.'%')
           ->orWhere('sth_other', '=', '%'.$xxxx.'%')
           ->orWhere(...)
           ...
           ->get();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用列值过滤器查询并获取原始值的最后一个值?

对除最后一个值以外的所有值使用过滤器

Django过滤器,如果查询中只有最后一个值为真

PHP的数组过滤器数组只有一个属性值

SQL 在外部查询中添加一个过滤器以应用于所有子查询

第一个密码查询(子查询)的基于过滤器的输出

如何基于另一个过滤器中的选择来控制过滤器的值

基于2个值的COUNTA查询/过滤器

Power BI - 按某一列测量除一个之外的所有过滤器都保留/忽略过滤器的位置

基于最后一个索引的列表嵌入字段上的Mongoengine过滤器查询

使用一个静态过滤器的基于Hibernate Apache Lucene的全文本搜索

如何使用json_query过滤器提取等于一个值的所有项目

基于另一个过滤器数组

Solr对多个过滤器查询与一个过滤器查询的性能差异

基于来自另一个数组的值的Typescript过滤器数组

基于一个布尔值的Java 8过滤器

寻找一个jq过滤器以基于嵌套属性的值排除嵌套对象

如何基于另一个列表中一个属性的所有值来过滤linq查询

跳过基于另一个过滤器ASP .NET的过滤器执行

如何定义一个过滤器,为 Spring Data 中的所有查询附加一个额外的 where 条件

如果没有过滤选项,如何编写一个sql显示基于过滤器的数量结果并合并两个不同的列?

在 Vue.js 中每列需要一个文本过滤器

Grails安全过滤器除一个动作外的所有动作

一个衬里用过滤器去除阵列中所有出现的子串?

DAX ALLEXCEPT:如何删除除一个以外的所有过滤器?

过滤器和 stristr():查找除第一个以外的所有单词

对除一个元素之外的所有元素应用过滤器

QFileDialog为所有支持的图像格式创建一个过滤器

查询SQL表以根据另一列中的过滤器获取一列中的所有新值