久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <tfoot id='TO96a'></tfoot>
      <i id='TO96a'><tr id='TO96a'><dt id='TO96a'><q id='TO96a'><span id='TO96a'><b id='TO96a'><form id='TO96a'><ins id='TO96a'></ins><ul id='TO96a'></ul><sub id='TO96a'></sub></form><legend id='TO96a'></legend><bdo id='TO96a'><pre id='TO96a'><center id='TO96a'></center></pre></bdo></b><th id='TO96a'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TO96a'><tfoot id='TO96a'></tfoot><dl id='TO96a'><fieldset id='TO96a'></fieldset></dl></div>
    1. <small id='TO96a'></small><noframes id='TO96a'>

      • <bdo id='TO96a'></bdo><ul id='TO96a'></ul>
      <legend id='TO96a'><style id='TO96a'><dir id='TO96a'><q id='TO96a'></q></dir></style></legend>
    2. laravel 搜索多個以空格分隔的單詞

      laravel search multiple words separated by space(laravel 搜索多個以空格分隔的單詞)

      <small id='glRqp'></small><noframes id='glRqp'>

      <tfoot id='glRqp'></tfoot>

        <bdo id='glRqp'></bdo><ul id='glRqp'></ul>

                <i id='glRqp'><tr id='glRqp'><dt id='glRqp'><q id='glRqp'><span id='glRqp'><b id='glRqp'><form id='glRqp'><ins id='glRqp'></ins><ul id='glRqp'></ul><sub id='glRqp'></sub></form><legend id='glRqp'></legend><bdo id='glRqp'><pre id='glRqp'><center id='glRqp'></center></pre></bdo></b><th id='glRqp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='glRqp'><tfoot id='glRqp'></tfoot><dl id='glRqp'><fieldset id='glRqp'></fieldset></dl></div>
                  <tbody id='glRqp'></tbody>
                <legend id='glRqp'><style id='glRqp'><dir id='glRqp'><q id='glRqp'></q></dir></style></legend>
              1. 本文介紹了laravel 搜索多個以空格分隔的單詞的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我是 laravel 查詢構建器的新手,我想搜索在輸入字段中輸入的多個單詞,例如,如果我輸入jhon doe",我想獲取包含 jhon 或 doe 的任何列

                I am new to laravel query builder, I want to search multiple words entered in an input field for example if I type "jhon doe" I want to get any column that contains jhon or doe

                我已經看到/嘗試過使用 php MySQL 的解決方案,但無法適應查詢構建器

                I have seen/tried solutions using php MySQL but can't able to adapt to query builder

                //1. exploding the space between the keywords 
                
                //2. using foreach apend the query together
                
                $query = "select * from users where";
                
                $keywordRaw = "jhon doe";
                $keywords = explode(' ', $keywordRaw );
                foreach ($keywords as $keyword){
                $query.= " first_name LIKE '%" + $keyword +"%' OR ";
                }
                

                如何使用查詢構建器執行此操作

                how do I do this using query builder

                這是我到目前為止所擁有的,這樣做的正確方法是什么,

                this is what i have so far, what is the proper way of doing this,

                $keywordRaw = "jhon doe";
                //how do I explode this words and append them along with their appropriate query
                $users = User::select('users.*')
                ->where('first_name', 'LIKE', '%'.$keywordRaw.'%')
                

                請幫忙,提前致謝

                推薦答案

                這就是您使用 QueryBuilder 的方式,但首先要補充一些注意事項:

                This is how you do it with QueryBuilder, but first some additional notes:

                // user can provide double space by accident, or on purpose:
                $string = 'john  doe';
                
                // so with explode you get this:
                explode(' ', $string);
                array(
                  0 => 'john',
                  1 => '',
                  2 => 'doe'
                )
                
                // Now if you go with LIKE '%'.value.'%', you get this:
                select * from table where name like '%john%' or name like '%%' or ...
                

                也就是說,您顯然不能依賴 explode,因為在上述情況下,您將獲得所有行.

                That said, you obviously can't rely on explode because in the above case you would get all the rows.

                所以,這是你應該做的:

                So, this is what you should do:

                $string = 'john  doe';
                
                // split on 1+ whitespace & ignore empty (eg. trailing space)
                $searchValues = preg_split('/s+/', $string, -1, PREG_SPLIT_NO_EMPTY); 
                
                $users = User::where(function ($q) use ($searchValues) {
                  foreach ($searchValues as $value) {
                    $q->orWhere('name', 'like', "%{$value}%");
                  }
                })->get();
                

                where 中有閉包,因為將 或 where 子句括在括號中是一種很好的做法.例如,如果您的 User 模型使用了 SoftDeletingScope 而您不按照我的建議去做,那么您的整個查詢就會搞砸.

                There is closure in the where because it is a good practice to wrap your or where clauses in parentheses. For example if your User model used SoftDeletingScope and you would not do what I suggested, your whole query would be messed up.

                這篇關于laravel 搜索多個以空格分隔的單詞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                  <tbody id='eDnrw'></tbody>
                <legend id='eDnrw'><style id='eDnrw'><dir id='eDnrw'><q id='eDnrw'></q></dir></style></legend>
              2. <i id='eDnrw'><tr id='eDnrw'><dt id='eDnrw'><q id='eDnrw'><span id='eDnrw'><b id='eDnrw'><form id='eDnrw'><ins id='eDnrw'></ins><ul id='eDnrw'></ul><sub id='eDnrw'></sub></form><legend id='eDnrw'></legend><bdo id='eDnrw'><pre id='eDnrw'><center id='eDnrw'></center></pre></bdo></b><th id='eDnrw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eDnrw'><tfoot id='eDnrw'></tfoot><dl id='eDnrw'><fieldset id='eDnrw'></fieldset></dl></div>

                <small id='eDnrw'></small><noframes id='eDnrw'>

                  <bdo id='eDnrw'></bdo><ul id='eDnrw'></ul>

                  <tfoot id='eDnrw'></tfoot>

                          主站蜘蛛池模板: 欧美在线播放一区 | 久久丝袜视频 | 日韩视频一区在线观看 | 精品伊人久久 | 九色网址 | 在线观看亚洲一区二区 | 中文字幕一区二区三区不卡 | 免费成人高清在线视频 | 日韩成人 | 国产精品久久久久久 | 精精国产xxxx视频在线播放 | 亚洲一区中文字幕 | 亚洲美女网站 | 亚洲视频免费在线观看 | 成人性视频免费网站 | 欧美日日 | 欧美一区二区在线 | 亚洲欧美在线观看 | 欧美日韩国产一区二区三区 | 夜夜久久 | 中文字幕在线播放第一页 | 日韩专区中文字幕 | 瑟瑟视频在线看 | 亚洲成人一级 | 天天天天操| 国产中文字幕在线 | av官网在线 | av看片网站 | 91久久国产综合久久 | 夜夜操天天干 | 免费久久久久久 | 免费视频一区 | 亚洲狠狠丁香婷婷综合久久久 | 日韩在线欧美 | 国产高清精品一区二区三区 | 91精品麻豆日日躁夜夜躁 | 精品一区二区三区中文字幕 | 精品欧美乱码久久久久久1区2区 | 99r在线| 亚洲人在线观看视频 | 国产一区二区精品在线观看 |