佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > Laravel模糊查詢區(qū)分大小寫(xiě)的實(shí)例

Laravel模糊查詢區(qū)分大小寫(xiě)的實(shí)例

熱門(mén)標(biāo)簽:銀行業(yè)務(wù) 電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) Mysql連接數(shù)設(shè)置 團(tuán)購(gòu)網(wǎng)站 服務(wù)器配置 Linux服務(wù)器 阿里云

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è)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • 對(duì)laravel in 查詢的使用方法詳解
  • laravel多條件查詢方法(and,or嵌套查詢)

標(biāo)簽:棗莊 大理 蚌埠 衡水 萍鄉(xiāng) 江蘇 廣元 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Laravel模糊查詢區(qū)分大小寫(xiě)的實(shí)例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    漳州市| 屏东县| 钟祥市| 巫山县| 济南市| 喀喇沁旗| 河西区| 大理市| 沾益县| 光泽县| 横山县| 丰都县| 浦县| 安多县| 根河市| 鄂州市| 金川县| 固镇县| 神木县| 永春县| 金沙县| 延庆县| 且末县| 巴中市| 留坝县| 青神县| 兰溪市| 介休市| 密云县| 惠水县| 亳州市| 宁波市| 阳江市| 昌图县| 农安县| 抚松县| 额敏县| 宣恩县| 长顺县| 山东| 澎湖县|