Laravel的ORM特殊操作!
举个例子:我们数据库设计的编码方式如果是ci,也就是说大小写不敏感的话,我们搜索的时候,搜索test,那么结果是Test,test,teST等等都出来,但是我们加上like binary的话,那么搜索出来的就是test,不管你的mysql数据库是什么编码排序规则。
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# 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”
]
|
参考文件位置:
?
1
|
D:\\phpStudy\\WWW\\BCCAdminV1.0\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Query\\Builder.php
|
?
1
2
3
4
5
6
7
8
|
protected $bindings = [
'select' => [],
'join' => [],
'where' => [],
'having' => [],
'order' => [],
'union' => [],
];
|
?
1
2
3
4
5
6
7
8
|
protected $operators = [
'=' , '<' , '>' , '<=' , '>=' , '<>' , '!=' ,
'like' , 'like binary' , 'not like' , 'between' , 'ilike' ,
'&' , '|' , '^' , '<<' , '>>' ,
'rlike' , 'regexp' , 'not regexp' ,
'~' , '~*' , '!~' , '!~*' , 'similar to' ,
'not similar to' ,
];
|
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
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模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持快网idc。
原文链接:https://blog.csdn.net/zhezhebie/article/details/78342153
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
Linux下进程管理工具Supervisor的安装配置和基本使用
2025-05-27 54 -
2025-06-04 55
-
2025-05-25 22
-
2025-05-25 35
-
2025-05-29 98
热门评论