Laravel模糊查询区分大小写的实例
发布:smiling 来源: PHP粉丝网 添加日期:2021-12-25 15:44:27 浏览: 评论:0
今天小编就为大家分享一篇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:\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'));
- }
Tags: Laravel模糊查询
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)