Laravel模糊查询区分大小写的实例
Laravel的ORM特殊操作!
举个例子:我们数据库设计的编码方式如果是ci,也就是说大小写不敏感的话,我们搜索的时候,搜索test,那么结果是Test,test,teST等等都出来,但是我们加上likebinary的话,那么搜索出来的就是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=>“likebinary” 9=>“notlike” 10=>“between” 11=>“ilike” 12=>“&” 13=>“|” 14=>“^” 15=>“<<” 16=>“>>” 17=>“rlike” 18=>“regexp” 19=>“notregexp” 20=>“~” 21=>“~*” 22=>“!~” 23=>“!~*” 24=>“similarto” 25=>“notsimilarto” ]
参考文件位置:
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','likebinary','notlike','between','ilike', '&','|','^','<<','>>', 'rlike','regexp','notregexp', '~','~*','!~','!~*','similarto', 'notsimilarto', ];
publicfunctionindex($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','likebinary','%'.$search.'%')
->orWhere('nick_name','likebinary','%'.$search.'%')
->orWhere('phone','likebinary','%'.$search.'%')
->orWhere('email','likebinary','%'.$search.'%');
}
})
->orderBy('create_time','desc')
->paginate($perPage);
//追加额外参数,例如搜索条件
$appendData=$data->appends(array(
'search'=>$search,
'perPage'=>$perPage,
));
returnview('admin/customer/customerList',compact('data'));
}
以上这篇Laravel模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。