• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    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模糊查询区分大小写的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

    您可能感兴趣的文章:
    • 对laravel in 查询的使用方法详解
    • laravel多条件查询方法(and,or嵌套查询)
    上一篇:基于laravel Request的所有方法详解
    下一篇:laravel5表单唯一验证的实例代码
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    Laravel模糊查询区分大小写的实例 Laravel,模糊,查询,区分,大小,