Laravel模糊查询区分大小写的实例


Posted in PHP onSeptember 29, 2019

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:\phpStudy\WWW\BCCAdminV1.0\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.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模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

PHP 相关文章推荐
信用卡效验程序
Oct 09 PHP
一个PHP日历程序
Dec 06 PHP
PHP XML操作的各种方法解析(比较详细)
Jun 17 PHP
PHP原生模板引擎 最简单的模板引擎
Apr 25 PHP
PHP Error与Logging函数的深入理解
Jun 03 PHP
PHP5.5和之前的版本empty函数的不同之处
Jun 13 PHP
php中smarty变量修饰用法实例分析
Jun 11 PHP
PHP实现无限分类的实现方法
Nov 14 PHP
PHP实现的文件上传类与用法详解
Jul 05 PHP
Laravel框架模板加载,分配变量及简单路由功能示例
Jun 11 PHP
php实现微信小程序授权登录功能(实现流程)
Nov 13 PHP
phpStorm2020 注册码
Sep 17 PHP
基于laravel Request的所有方法详解
Sep 29 #PHP
基于Laravel 5.2 regex验证的正确写法
Sep 29 #PHP
php实现对文件压缩简单的方法
Sep 29 #PHP
Laravel 添加多语言提示信息的方法
Sep 29 #PHP
php实现登录页面的简单实例
Sep 29 #PHP
php实现推荐功能的简单实例
Sep 29 #PHP
php实现分页功能的详细实例方法
Sep 29 #PHP
You might like
php简单开启gzip压缩方法(zlib.output_compression)
2013/04/13 PHP
php一次性删除前台checkbox多选内容的方法
2013/09/22 PHP
PHP获取服务器端信息的方法
2014/11/28 PHP
详解配置 Apache 服务器支持 PHP 文件的解析
2017/02/15 PHP
前淘宝前端开发工程师阿当的PPT中有JS技术理念问题
2010/01/15 Javascript
JavaScript CSS修改学习第三章 修改样式表
2010/02/19 Javascript
基于jQuery UI CSS Framework开发Widget的经验
2010/08/21 Javascript
$.get获取一个文件的内容示例代码
2013/09/11 Javascript
js传中文参数controller里获取参数乱码问题解决方法
2014/01/03 Javascript
javascript创建createXmlHttpRequest对象示例代码
2014/02/10 Javascript
javascript简单实现跟随滚动条漂浮的返回顶部按钮效果
2016/08/19 Javascript
js实现3d悬浮效果
2017/02/16 Javascript
vue加载自定义的js文件方法
2018/03/13 Javascript
JavaScript引用类型Object常见用法实例分析
2018/08/08 Javascript
Vue2.x中利用@font-size引入字体图标报错的解决方法
2018/09/28 Javascript
Array.filter中如何正确使用Async
2020/11/04 Javascript
[02:27]《DAC最前线》之附加赛征程
2015/01/29 DOTA
Python爬虫实战:分析《战狼2》豆瓣影评
2018/03/26 Python
python3.7 利用函数os pandas利用excel对文件名进行归类
2019/09/29 Python
Python可变对象与不可变对象原理解析
2020/02/25 Python
python pyqtgraph 保存图片到本地的实例
2020/03/14 Python
PyCharm 2020 激活到 2100 年的教程
2020/03/25 Python
Django ORM 查询表中某列字段值的方法
2020/04/30 Python
在Sublime Editor中配置Python环境的详细教程
2020/05/03 Python
python中实现栈的三种方法
2020/12/19 Python
美国家用电器和电子产品商店:Abt
2016/09/06 全球购物
KLOOK客路:发现更好玩的世界,预订独一无二的旅行体验
2016/12/16 全球购物
FILA斐乐中国官方商城:意大利运动品牌
2017/01/25 全球购物
瑞典香水、须后水和美容产品购物网站:Parfym-Klick.se
2019/12/29 全球购物
企业给企业的表扬信
2014/01/13 职场文书
企业后勤岗位职责
2014/02/28 职场文书
设计大赛策划方案
2014/06/13 职场文书
学校宣传标语
2014/06/18 职场文书
学雷锋献爱心倡议书
2015/04/27 职场文书
杨善洲观后感
2015/06/04 职场文书
mysql下的max_allowed_packet参数设置详解
2022/02/12 MySQL