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

<legend id='L0OQ7'><style id='L0OQ7'><dir id='L0OQ7'><q id='L0OQ7'></q></dir></style></legend>

    <tfoot id='L0OQ7'></tfoot>
        <bdo id='L0OQ7'></bdo><ul id='L0OQ7'></ul>

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

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

    2. 在 Eloquent 中按自定義順序?qū)线M行排序

      Sort collection by custom order in Eloquent(在 Eloquent 中按自定義順序?qū)线M行排序)

    3. <legend id='hhX6N'><style id='hhX6N'><dir id='hhX6N'><q id='hhX6N'></q></dir></style></legend>
          <tbody id='hhX6N'></tbody>

        <tfoot id='hhX6N'></tfoot>

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

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

                <i id='hhX6N'><tr id='hhX6N'><dt id='hhX6N'><q id='hhX6N'><span id='hhX6N'><b id='hhX6N'><form id='hhX6N'><ins id='hhX6N'></ins><ul id='hhX6N'></ul><sub id='hhX6N'></sub></form><legend id='hhX6N'></legend><bdo id='hhX6N'><pre id='hhX6N'><center id='hhX6N'></center></pre></bdo></b><th id='hhX6N'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hhX6N'><tfoot id='hhX6N'></tfoot><dl id='hhX6N'><fieldset id='hhX6N'></fieldset></dl></div>
                本文介紹了在 Eloquent 中按自定義順序?qū)线M行排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我有一組 ID,如下所示:

                I have an array of ID's as follows:

                $ids = [5,6,0,1]
                

                使用 Eloquent,我可以使用 ->whereIn('id', $ids) 函數(shù)搜索這些 Id.正如預(yù)期的那樣,這將按 Id 以升序返回結(jié)果,有沒有辦法可以按數(shù)組所在的順序返回結(jié)果?或者,按 $ids 數(shù)組的順序轉(zhuǎn)換集合的最簡單方法是什么?

                Using Eloquent I am able to search for these Id's using the ->whereIn('id', $ids) function. This as expected will return the results in the ascending order by Id, is there a way I can return the results on the order the array is in? alternatively whats the easiest way to convert the collection in the order of the $ids array?

                推薦答案

                如果您希望記錄按特定順序排列,則必須使用 收集方法:

                If there's a specific order you'd like the records in, you'd have to use the Collection Methods:

                要按照您指定的特定順序獲取 ID,您可以使用 sortBy 方法,如下所示,其中 collection 是您的模型集合:

                To get your ID's in the very specific order you've specified, you can make use of the sortBy method as follows, where collection is your collection of models:

                $ids = [ 5, 6, 0, 1];
                
                $sorted = $collection->sortBy(function($model) use ($ids) {
                    return array_search($model->getKey(), $ids);
                });
                
                // [ 5, 6, 0, 1] // (desired order)
                

                要隨機化您的集合,您可以使用 shuffle 方法.

                To randomize your collection you can make use of the shuffle method.

                $collection = collect([1, 2, 3, 4, 5]);
                
                $shuffled = $collection->shuffle();
                
                $shuffled->all();
                
                // [3, 2, 5, 1, 4] // (generated randomly)
                

                請參閱 shuffle 上的 Laravel 文檔 和/或 sortBy 以獲得更具體的要求.

                See the Laravel Docs on shuffle and/or sortBy for more specific requirements.

                如果您沒有真正考慮特定的順序,您可以在 5.2 及更高版本中使用 ->inRandomOrder(),舊版本將需要使用 - 的原始查詢>orderBy(DB::raw('RAND()')).

                If you don't really have a specific order in mind, you can use ->inRandomOrder() in version 5.2 and up, older versions would require the raw query using ->orderBy(DB::raw('RAND()')).

                這篇關(guān)于在 Eloquent 中按自定義順序?qū)线M行排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                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 和魔術(shù)方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

                  <bdo id='8KF8L'></bdo><ul id='8KF8L'></ul>

                    <i id='8KF8L'><tr id='8KF8L'><dt id='8KF8L'><q id='8KF8L'><span id='8KF8L'><b id='8KF8L'><form id='8KF8L'><ins id='8KF8L'></ins><ul id='8KF8L'></ul><sub id='8KF8L'></sub></form><legend id='8KF8L'></legend><bdo id='8KF8L'><pre id='8KF8L'><center id='8KF8L'></center></pre></bdo></b><th id='8KF8L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8KF8L'><tfoot id='8KF8L'></tfoot><dl id='8KF8L'><fieldset id='8KF8L'></fieldset></dl></div>
                      <tbody id='8KF8L'></tbody>
                    • <tfoot id='8KF8L'></tfoot>

                      <legend id='8KF8L'><style id='8KF8L'><dir id='8KF8L'><q id='8KF8L'></q></dir></style></legend>
                    • <small id='8KF8L'></small><noframes id='8KF8L'>

                        1. 主站蜘蛛池模板: 国产区一区二区三区 | 99精品亚洲国产精品久久不卡 | 国产精品久久久久久久久免费丝袜 | 免费国产视频在线观看 | 婷婷久久网 | 亚洲免费福利视频 | 久久精品 | 日韩成人中文字幕 | 91精品久久久久久久久久 | 精品久久久久久 | 一本岛道一二三不卡区 | 欧美天堂| 中文日韩在线视频 | 精品久久久久久久久久 | 亚洲三区在线 | 人人九九精 | 国产一区二区三区在线视频 | 色综合色综合网色综合 | av色站| 久草视频在线播放 | 国产精品久久久久久久久久久新郎 | 成人午夜视频在线观看 | 欧美一区二区三区大片 | 国产99免费| 国产美女久久久 | 亚洲美女一区 | 国产高清视频在线观看 | 久久久www成人免费无遮挡大片 | 毛片a | 99精品在线观看 | 久久久91精品国产一区二区精品 | 日韩成人在线免费观看 | jlzzxxxx18hd护士| 国内激情av片 | 怡红院成人在线视频 | 亚洲视频二区 | 在线国产精品一区 | 国产成人久久精品一区二区三区 | 国产精品有限公司 | 综合精品在线 | 成人精品一区二区三区中文字幕 |