温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在Laravel中实现模糊查询区分大小写

发布时间:2021-03-19 15:49:30 来源:亿速云 阅读:213 作者:Leah 栏目:开发技术

本篇文章给大家分享的是有关怎么在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')); }

以上就是怎么在Laravel中实现模糊查询区分大小写,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI