您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關怎么在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中實現模糊查詢區分大小寫,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。