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

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

    <tfoot id='XkotX'></tfoot>
      • <bdo id='XkotX'></bdo><ul id='XkotX'></ul>
    1. <small id='XkotX'></small><noframes id='XkotX'>

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

        Laravel 按 hasmany 關系排序

        Laravel order by hasmany relationship(Laravel 按 hasmany 關系排序)

          <tbody id='8MvBe'></tbody>
        <legend id='8MvBe'><style id='8MvBe'><dir id='8MvBe'><q id='8MvBe'></q></dir></style></legend>

            <tfoot id='8MvBe'></tfoot>

            <small id='8MvBe'></small><noframes id='8MvBe'>

              • <bdo id='8MvBe'></bdo><ul id='8MvBe'></ul>
                • <i id='8MvBe'><tr id='8MvBe'><dt id='8MvBe'><q id='8MvBe'><span id='8MvBe'><b id='8MvBe'><form id='8MvBe'><ins id='8MvBe'></ins><ul id='8MvBe'></ul><sub id='8MvBe'></sub></form><legend id='8MvBe'></legend><bdo id='8MvBe'><pre id='8MvBe'><center id='8MvBe'></center></pre></bdo></b><th id='8MvBe'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8MvBe'><tfoot id='8MvBe'></tfoot><dl id='8MvBe'><fieldset id='8MvBe'></fieldset></dl></div>
                  本文介紹了Laravel 按 hasmany 關系排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有兩個 eloquent 模型 ThreadsComments ,每個線程都有很多評論.

                  I have two eloquent models Threads and Comments , each thread hasMany comments.

                  在列出線程時,我需要按 created_at 降序對線程進行排序.因此,我需要在 Comments 中使用 created at 對線程進行排序.

                  While listing the threads, i need to order the threads by the created_at descending. So , i need to sort the threads using created at in Comments.

                  顯然點符號對這種排序沒有幫助,我如何正確排序線程?

                  Apparently dot notation isn't helpful in ordering this way, how do i order the Threads correctly ?

                  $Threads= Thread::all()->orderBy("comment.created_at","desc")
                  

                  推薦答案

                  了解 Laravel 的預加載是如何工作的很重要.如果我們急切加載您的示例,Laravel 首先獲取所有線程.然后它獲取所有評論并將它們添加到線程對象.由于使用了單獨的查詢,因此無法按注釋對線程進行排序.

                  It's important to understand how Laravel's eager loading works. If we eager load your example, Laravel first fetches all threads. Then it fetches all comments and adds them to the threads object. Since separate queries are used, it isn't possible to order threads by comments.

                  您需要改用連接.請注意,我在此示例中猜測您的表/列名稱.

                  You need to use a join instead. Note that I'm guessing at your table/column names in this example.

                  $threads = Thread::leftJoin('comment', 'comment.thread_id', '=', 'thread.id')
                      ->with('comments')
                      ->orderBy('comment.created_at', 'desc')
                      ->get();
                  

                  自從您加入后,您可能需要手動指定列以選擇您的表格列名.

                  Since you're joining, you might need to manually specify columns to select your tables column names.

                  $threads = Thread::select('thread.*')->leftJoin('comment', 'comment.thread_id', '=', 'thread.id')
                      ->with('comments')
                      ->orderBy('comment.created_at', 'desc')
                      ->get();
                  

                  這篇關于Laravel 按 hasmany 關系排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)

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

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

                            <tfoot id='dub44'></tfoot>
                              <tbody id='dub44'></tbody>
                            主站蜘蛛池模板: 久久人 | 国产精品毛片 | 欧美一级毛片久久99精品蜜桃 | 亚洲精品电影网在线观看 | 日韩av电影院 | 国产精品女人久久久 | 国产精品1区 | 青青草亚洲 | 欧美一级在线观看 | 成人在线视频一区二区三区 | 成人影院免费视频 | 午夜久久久 | 亚洲有码转帖 | 在线免费看黄 | 日韩电影中文字幕 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 91久久久久久久久久久久久 | 精品视频在线播放 | av网站在线播放 | 免费在线视频一区二区 | 激情 婷婷| 不用播放器看的av | www.亚洲免费 | 国产精品视频久久久 | 国产乱人伦 | 毛片一级片| 韩日一区 | 欧美一区二区三区在线观看 | 久久婷婷国产麻豆91 | 青青草免费在线视频 | 黄色一级电影在线观看 | 九九热在线精品视频 | 欧美日韩国产一区二区 | 欧美日韩一本 | 国产三区视频在线观看 | av在线天堂 | 五月婷婷激情 | 成人三级在线观看 | 成人美女免费网站视频 | 蜜桃av人人夜夜澡人人爽 | 51ⅴ精品国产91久久久久久 |