久久久久久久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>
                            主站蜘蛛池模板: 欧美日韩一区在线播放 | 国产高清在线视频 | 天天综合网91 | 久久精品16| 国产精品99久久久久 | 日本一区二区电影 | 伊人精品久久久久77777 | 精品国产31久久久久久 | 在线成人www免费观看视频 | 色播av| 亚洲国内精品 | 国产精品99久久久久久久vr | 国产在线中文字幕 | 亚洲国产成人av好男人在线观看 | 国产精品美女一区二区三区 | 国产一级片在线播放 | 午夜午夜精品一区二区三区文 | www.精品国产 | 国产综合在线视频 | 亚洲国产一区二区三区 | 精品久久国产老人久久综合 | 亚洲在线久久 | 特一级毛片 | 欧美福利视频 | 日日干夜夜操 | 中文字幕11页 | 蜜臀久久 | 亚洲精品二区 | 激情影院久久 | 精品中文字幕一区二区三区 | 国产视频中文字幕 | 国产精品亚洲精品日韩已方 | 亚洲日韩中文字幕一区 | 亚洲欧美在线视频 | 视频一二三区 | 国产一级淫片免费视频 | 久久久久国产一区二区三区不卡 | 国产999精品久久久 午夜天堂精品久久久久 | 中文字幕av一区二区三区 | 精品一区二区三区四区 | 成人在线播放网站 |