Laravel模糊查詢區分大小寫

來源:互聯網
上載者:User
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'));}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.