Laravel模糊查询区分大小写的实例
2019-09-29 17:29
1701 查看
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模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
相关文章推荐
- Laravel模糊查询区分大小写
- 搜索框模糊查询--关键字查询,不区分大小写并且设备高亮显示
- 查询语句中不区分大小写和区分大小写及其模糊查询 的语句
- Oracle 模糊查询不区分大小写
- sqlserver中like模糊查询如何区分大小写
- MySql解决不区分大小写和中文模糊查询问题
- sqlite 模糊查询不区分大小写,以及区分大小写语句
- ilike---不区分大小写的模糊查询
- XSLT模糊查询函数contains不区分大小写,for-each排序
- MySQL模糊查询(like)时区分大小写
- oracle 模糊查询不区分大小写 regexp_like
- hbase RowFilter如何根据rowkey查询以及实例实现代码 habase模糊查询【转】
- Mysql如何在SQL中实现区分大小写的查询
- 解决MySQL查询不区分大小写
- SQLite区分大小写查询
- 如何在SQL模糊查询中忽略对大小写字符的处理
- pgsql查询优化之模糊查询实例详解
- unix系统,如何查询同目录下的同名(不区分大小写)文件
- 模糊查询——忽略大小写小技巧
- sql按相似度模糊查询实例