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

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

    3. <tfoot id='ocE3Z'></tfoot>

      Laravel 雄辯的計數(shù)關系

      Laravel eloquent counting a relation(Laravel 雄辯的計數(shù)關系)

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

          <small id='7Tkl3'></small><noframes id='7Tkl3'>

          • <bdo id='7Tkl3'></bdo><ul id='7Tkl3'></ul>
                本文介紹了Laravel 雄辯的計數(shù)關系的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我是 laravel 和 eloquent 的新手,我不確定這是否可能.但我有 2 張表具有一對多的關系.一種是位置",一種是用戶".一個位置可以有多個用戶.

                I'm new to laravel and eloquent and I'm not sure if this is even possible. but I have 2 tables with a one to many relationship. One is "locations" and one is "users". One location can have many users.

                因此,如果我想獲取所有用戶的所有位置,我會這樣做:

                So if I wanted to get all locations with all users I would just do this:

                Location::with("users")->get();
                

                但我也想知道每個位置有多少用戶,我嘗試這樣做

                But I also want to know how many users each location has, I tried doing this

                Location::with("users")->count("users")->get();
                

                但這沒有用.

                推薦答案

                如果您使用預先加載,則不會出現(xiàn)提到的 n+1 問題.

                The n+1 issue that was mentioned doesn't occur if you use eager loading.

                $locations = Location::with('users')->get();
                
                $locations->users()->count();
                

                無論您有多少用戶或位置,這都會產生三個查詢.

                This should result in three queries, no matter how many users or locations you have.

                • 對位置模型進行計數(shù)查詢
                • 從位置選擇 *
                • select * from users where in

                混淆是因為這也有效:

                $locations = Location::all();
                
                $locations->users()->count();
                

                但在這種情況下,它會為每個位置查詢一次.

                But in this case, it does query once for each location.

                查看文檔了解更多信息:http://laravel.com/docs/eloquent#eager-loading

                See the docs for more info: http://laravel.com/docs/eloquent#eager-loading

                這篇關于Laravel 雄辯的計數(shù)關系的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(liá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 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

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

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

                            <tbody id='dXGvu'></tbody>

                          主站蜘蛛池模板: 日韩有码一区 | av一区二区三区四区 | 成人在线观看免费视频 | 国产精品99久久久久 | 日韩欧美国产一区二区 | 97精品国产97久久久久久免费 | 视频三区 | 欧美性久久久 | 亚州精品天堂中文字幕 | 亚洲一区二区精品视频在线观看 | 一区二区三区欧美在线观看 | 亚洲人在线观看视频 | 国产一区二区三区免费 | 国产草草视频 | 毛片一区二区 | 99色综合 | 一区二区在线 | 欧美 中文字幕 | 一区二区精品 | 国产在线观看 | 夜夜爆操 | 国产视频91在线 | 成年视频在线观看福利资源 | 男人亚洲天堂 | 国产99久久精品 | 国产一区在线免费 | 精品久久久久久亚洲精品 | 国产ts人妖另类 | 欧美成人一区二区 | 性色视频 | 久久一 | 日韩精品在线视频免费观看 | 欧美一区视频在线 | 精品国产一区二区在线 | 国产精品二区三区 | 自拍偷拍第1页 | 精品国产视频 | 亚洲天堂av在线 | 国产成人精品999在线观看 | 亚洲激情视频在线 | 欧区一欧区二欧区三免费 |