Laravel模糊查詢區(qū)分大小寫(xiě)的實(shí)例
Laravel的ORM特殊操作!
舉個(gè)例子:我們數(shù)據(jù)庫(kù)設(shè)計(jì)的編碼方式如果是ci,也就是說(shuō)大小寫(xiě)不敏感的話,我們搜索的時(shí)候,搜索test,那么結(jié)果是Test,test,teST等等都出來(lái),但是我們加上like binary的話,那么搜索出來(lái)的就是test,不管你的mysql數(shù)據(jù)庫(kù)是什么編碼排序規(guī)則。
#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 => “l(fā)ike” 8 => “l(fā)ike 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); //追加額外參數(shù),例如搜索條件 $appendData = $data->appends(array( 'search' => $search, 'perPage' => $perPage, )); return view('admin/customer/customerList', compact('data')); }
以上這篇Laravel模糊查詢區(qū)分大小寫(xiě)的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Yii2中多表關(guān)聯(lián)查詢hasOne hasMany的方法
這篇文章主要介紹了Yii2中多表關(guān)聯(lián)查詢hasOne hasMany的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-02-02php微信開(kāi)發(fā)之音樂(lè)回復(fù)功能
這篇文章主要為大家詳細(xì)介紹了php微信開(kāi)發(fā)之音樂(lè)回復(fù)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06PHP dirname簡(jiǎn)單使用代碼實(shí)例
這篇文章主要介紹了PHP dirname簡(jiǎn)單使用代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11php生成隨機(jī)密碼自定義函數(shù)代碼(簡(jiǎn)單快速)
創(chuàng)建大量用戶時(shí)一個(gè)一個(gè)想密碼是讓人頭疼的事,使用php隨機(jī)生成一個(gè)安全可靠的密碼,又方便又快捷,可以添加自己想的字符串,可以用在FTP密碼、Mysql密碼、網(wǎng)站后臺(tái)密碼等地方2014-05-05