Laravel模糊查询区分大小写的实例
时间:2022-07-27
本文章向大家介绍Laravel模糊查询区分大小写的实例,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
Laravel的ORM特殊操作!
举个例子:我们数据库设计的编码方式如果是ci,也就是说大小写不敏感的话,我们搜索的时候,搜索test,那么结果是Test,test,teST等等都出来,但是我们加上like binary的话,那么搜索出来的就是test,不管你的mysql数据库是什么编码排序规则。
#passthru: array:10 [▼
0 = “insert”
1 = “insertGetId”
2 = “getBindings”
3 = “toSql”
4 = “exists”
5 = “count”
6 = “min”
7 = “max”
8 = “avg”
9 = “sum”
]
#operators: array:26 [▼
0 = “=”
1 = “<”
2 = “ ”
3 = “<=”
4 = “ =”
5 = “< ”
6 = “!=”
7 = “like”
8 = “like binary”
9 = “not like”
10 = “between”
11 = “ilike”
12 = “&”
13 = “|”
14 = “^”
15 = “<<”
16 = “ ”
17 = “rlike”
18 = “regexp”
19 = “not regexp”
20 = “~”
21 = “~*”
22 = “!~”
23 = “!~*”
24 = “similar to”
25 = “not similar to”
]
参考文件位置:
D:phpStudyWWWBCCAdminV1.0vendorlaravelframeworksrcIlluminateDatabaseQueryBuilder.php
protected $bindings = [
'select' = [],
'join' = [],
'where' = [],
'having' = [],
'order' = [],
'union' = [],
];
protected $operators = [
'=', '<', ' ', '<=', ' =', '< ', '!=',
'like', 'like binary', 'not like', 'between', 'ilike',
'&', '|', '^', '<<', ' ',
'rlike', 'regexp', 'not regexp',
'~', '~*', '!~', '!~*', 'similar to',
'not similar to',
];
public function index($customer_type = null) {
$search = request('search');
$perPage = request('perPage') ? request('perPage') : 10;
$customer_type = $customer_type ? $customer_type : request('customer_type');
$data = Customer::select(['id', 'email', 'user_name', 'nick_name', 'status', 'phone', 'create_time'])
- where('customer_type', '=', $customer_type)
- where(function ($query) use ($search) {
if ($search) {
$query- where('user_name', 'like binary', '%' . $search . '%')
- orWhere('nick_name', 'like binary', '%' . $search . '%')
- orWhere('phone', 'like binary', '%' . $search . '%')
- orWhere('email', 'like binary', '%' . $search . '%');
}
})
- orderBy('create_time', 'desc')
- paginate($perPage);
//追加额外参数,例如搜索条件
$appendData = $data- appends(array(
'search' = $search,
'perPage' = $perPage,
));
return view('admin/customer/customerList', compact('data'));
}
以上这篇Laravel模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考。
- 通过单例模式模拟RAC连接 (r4笔记第76天)
- 网站上的验证码是怎么产生的?
- Java基础-17(01)总结,登录注册案例,Set集合,HashSet
- mongoDB初探第一篇(r4笔记第75天)
- 重温快速排序(r4笔记第73天)
- Java基础-17(01)总结,TreeSet,LinkHashSet
- 海量数据迁移之数据抽取流程 (r4笔记第72天)
- CSS Selectors Level 4新特性全面解析
- 巧用外部表避免大量的insert (r4笔记第71天)
- 如何用java语言实现C#中的ref关键字(按引用传递参数)的效果
- 16(01)总结List的子类,ArrayList,Vector,LinkedList
- 16(02)总结泛型
- 基于 React + Webpack 的音乐相册项目(上)
- 16(03)总结增强for循环,静态导入,可变参数
- php概述
- php教程
- php环境搭建
- PHP书写格式
- php变量
- php常量
- PHP注释
- php数组
- php字符串 string
- PHP整型 integer
- PHP浮点型 float
- php布尔型
- php数据类型之数组
- php数据类型之对象
- php数据类型之null
- php数据类型之间的转换
- php运算符
- php表达式
- PHP循环控制
- PHP流程控制
- php函数
- php全局变量
- PHP魔术变量
- php命名空间
- php 日期
- PHP包含文件
- php文件
- PHP 文件上传
- php Cookies
- php Sessions
- php email
- php安全email
- php错误处理
- PHP异常处理
- php过滤器
- PHP 高级过滤器
- php json
- php 表单
- PHP MySQL 简介
- PHP 连接 MySQL
- php创建数据库
- php 创建表
- php mysq 插入数据
- PHP MySQL 插入多条数据
- PHP MySQL 预处理语句
- php mysql 读取数据
- php mysql where
- PHP MySQL Order By
- PHP MySQL Update
- PHP MySQL Delete
- php ODBC
- Sony Z13 系列笔记本安装 NVIDIA 官方最新版显卡驱动程序
- 通过网页进行 iOS 应用内部分发
- 【DB笔试面试853】在Oracle中,什么是手动建库?手动建库有哪些步骤?
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机
- NHibernate 使用 SqlQuery
- 谈谈 INotifyPropertyChanged 的实现
- C 语言小知识
- 使用代码配置 NHibernate
- [Introduction]Go特殊的引用类型:值传递/指针传递/引用传递
- PythonforResearch | 0_语法基础
- iOS 系统中的视图动画
- 在 Android 的 /data 目录下添加虚拟内存
- 玩转安卓模拟器命令行
- 如何利用NLog输出结构化日志,并在Kibana优雅分析日志?
- Android 应用保存状态