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

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

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

    1. <legend id='Hqsvp'><style id='Hqsvp'><dir id='Hqsvp'><q id='Hqsvp'></q></dir></style></legend>
    2. <tfoot id='Hqsvp'></tfoot>

      按 created_at 對 Eloquent Collection 進行排序

      Sort Eloquent Collection by created_at(按 created_at 對 Eloquent Collection 進行排序)
        <bdo id='KGIBb'></bdo><ul id='KGIBb'></ul>
        <legend id='KGIBb'><style id='KGIBb'><dir id='KGIBb'><q id='KGIBb'></q></dir></style></legend>

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

              <tfoot id='KGIBb'></tfoot>

                  <tbody id='KGIBb'></tbody>

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

              • 本文介紹了按 created_at 對 Eloquent Collection 進行排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我有一個名為 'posts' 的表,其列有:'post_id int primary increments'、'poster_id int' 和 'status text' 以及一個名為 Friends 的數(shù)組,其列是:'user_id int primary' 和 'friend_ids文本'.

                I have a table named 'posts' with the columns: 'post_id int primary increments', 'poster_id int' and 'status text' as well as an array named friends with the columns: 'user_id int primary' and 'friend_ids text'.

                我需要獲取朋友文本列中的所有 ID,這很容易使用:

                I need to grab all the IDs in the friends text column which is easy enough using:

                $friends = explode(',', Friend::where('user_id', Sentry::getUser()->id)->first()->friend_ids);
                

                文本列中的數(shù)據(jù)看起來像1、2、3"等

                Where the data in the text column would look like '1,2,3,' etc.

                然后我創(chuàng)建一個 Eloquent Collection 對象,這也很容易通過:

                Then I create an Eloquent Collection object which is also easily done via:

                $posts = new IlluminateDatabaseEloquentCollection();
                

                但問題是我不知道如何填充集合并按 Post 對象的created_at"列對其內(nèi)容進行排序.

                But the problem is I can't figure out how to populate the collection and sort its contents by the Post object's 'created_at' column.

                這是我目前所擁有的:

                foreach ($friends as $id) {
                    $posts_ = Post::where('poster_id', $id)->getQuery()
                        ->orderBy('created_at', 'desc')
                        ->get();
                    foreach($posts_ as $post) {
                        $posts->add($post);
                    }
                }
                

                我不知道此代碼是否適用于按created_at"列對整個帖子集合進行排序.我還需要能夠輕松地對整個集合進行分頁.

                I can't figure out if this code would work or not for sorting the entire collection of posts by the 'created_at' column. I would also need to be able to paginate the entire collection easily.

                推薦的集合排序方式是什么?

                What is the recommended way of sorting the collection?

                推薦答案

                如果你想對 collection 進行排序,你可以使用 sortBy 方法按給定的鍵

                If you want to sort a collection you can use the sortBy method by given key

                $sorted = $posts->sortBy('created_at');
                

                您也可以在 collection

                $sorted = $posts->sortBy(function($post)
                {
                  return $post->created_at;
                });
                

                希望這會有所幫助.有關(guān) collections 的更多信息,您可以閱讀 docs

                Hope this helps. For more information on collections you can read the docs

                這篇關(guān)于按 created_at 對 Eloquent Collection 進行排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 可滾動游標(biāo)不起作用)
                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ū)動程序)

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

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

                        1. <tfoot id='YeoFU'></tfoot>
                            <tbody id='YeoFU'></tbody>
                        2. <i id='YeoFU'><tr id='YeoFU'><dt id='YeoFU'><q id='YeoFU'><span id='YeoFU'><b id='YeoFU'><form id='YeoFU'><ins id='YeoFU'></ins><ul id='YeoFU'></ul><sub id='YeoFU'></sub></form><legend id='YeoFU'></legend><bdo id='YeoFU'><pre id='YeoFU'><center id='YeoFU'></center></pre></bdo></b><th id='YeoFU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YeoFU'><tfoot id='YeoFU'></tfoot><dl id='YeoFU'><fieldset id='YeoFU'></fieldset></dl></div>
                          <legend id='YeoFU'><style id='YeoFU'><dir id='YeoFU'><q id='YeoFU'></q></dir></style></legend>
                          主站蜘蛛池模板: 国产精品.xx视频.xxtv | 综合二区| av手机免费在线观看 | 国产精品视频二区三区 | 国产日韩精品一区二区 | 精品久久久久久亚洲综合网 | 97免费在线视频 | 盗摄精品av一区二区三区 | 欧美a级成人淫片免费看 | 日本一区二区三区四区 | 天天插天天操 | 久久久www成人免费精品 | 国产成人精品免费视频大全最热 | 亚洲成人av在线播放 | 亚洲一区在线日韩在线深爱 | 午夜在线视频 | 精品欧美一区二区三区久久久 | 中文字幕av网址 | 精品91久久 | 日韩精品 电影一区 亚洲 | 日本一区二区三区在线观看 | 在线视频中文字幕 | 黑人粗黑大躁护士 | 免费毛片网 | 亚洲高清三级 | 亚洲一区二区三区免费在线观看 | 亚洲欧美日韩国产 | 亚洲电影成人 | 久久久久国产精品 | 国产精品一区二区av | 亚洲免费精品 | 国产精品99久久久久久动医院 | 日韩欧美在线免费观看 | 日韩三级一区 | 日本免费视频在线观看 | 91在线观看| 色综合一区二区三区 | 久久黄色网 | 久久一二区 | 天天夜碰日日摸日日澡 | 在线观看国产 |