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

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

  1. <small id='hgqOy'></small><noframes id='hgqOy'>

  2. <tfoot id='hgqOy'></tfoot>

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

        <bdo id='hgqOy'></bdo><ul id='hgqOy'></ul>
    1. Laravel eloquent按關系模型上的角色名稱排序

      Laravel eloquent sort by role name on relationship model(Laravel eloquent按關系模型上的角色名稱排序)
        <legend id='0c0cO'><style id='0c0cO'><dir id='0c0cO'><q id='0c0cO'></q></dir></style></legend>
          <tbody id='0c0cO'></tbody>

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

          1. <small id='0c0cO'></small><noframes id='0c0cO'>

                <bdo id='0c0cO'></bdo><ul id='0c0cO'></ul>
              • 本文介紹了Laravel eloquent按關系模型上的角色名稱排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我遇到了一個問題,我必須根據模型的關系數據對模型集合進行排序/排序.

                I'm stuck with a problem where I have to sort / order a collection of models by their relationship's data.

                我的設置如下:

                型號:UserTeamTeamUserRole

                TeamUser 模型是一個數據透視模型/表(包含 user_idteam_id.如果值得一提,我也使用 spatie/laravel-permissions角色.

                The TeamUser model is a pivot model / table (containing user_id and team_id. If it's worth mentioning I am also using spatie/laravel-permissions for the roles.

                如果我想按role.name 對團隊中的用戶進行排序,我該怎么做?我正在談論 Team 模型中的 users() 關系(請參閱代碼示例的進一步內容).一些用戶具有 team-leader 角色,大多數用戶具有 team-seller 角色.我試過做一個普通的 ..->sortBy('role.name') 但這似乎不起作用.如果有人可以幫助我,請提前致謝.

                How would I go forth when I want to sort the users in a team by their role.name? I'm talking about the users() relation in the Team model (see further down for code sample). Some users have the role team-leader and most have the role team-seller. I've tried doing a ordinary ..->sortBy('role.name') but that doesn't seem to work. Thanks in advance if anyone could help me out.

                User.php

                /**
                 * Team relation
                 *
                 * @return IlluminateDatabaseEloquentRelationsBelongsToMany
                 */
                public function team()
                {
                    return $this->belongsToMany('AppTeam', 'team_users', 'user_id', 'team_id');
                }
                

                Team.php

                /**
                 * User relation
                 *
                 * @return IlluminateDatabaseEloquentRelationsBelongsToMany
                 */
                public function users()
                {
                    return $this->belongsToMany('AppUser', 'team_users', 'team_id', 'user_id')->withTimestamps();
                }
                

                推薦答案

                如果要根據嵌套關系列對結果進行排序,則必須使用連接鏈:

                if you want to order the result based on nested relation column, you must use a chain of joins:

                $values = Team::query()
                      ->leftJoin('users', 'users.team_id', '=', 'teams.id')
                      ->leftJoin('model_has_roles', function ($join) {
                          $join->on('model_has_roles.model_id', '=', 'users.id')
                               ->where('model_has_roles.model_type', '=', 'appModelsUser');
                      })
                      ->leftJoin('roles', 'roles.id', '=', 'model_has_roles.role_id')
                      ->orderBy('roles.name')
                      ->get();
                

                我試過了,效果很好.

                請注意,如果您想按多列排序,您可以根據需要添加 'orderBy' 子句:

                please note that if you want to order by multiple columns you could add 'orderBy' clause as much as you want:

                ->orderBy('roles.name', 'DESC')->orderby('teams.name', 'ASC') //... ext
                

                這篇關于Laravel eloquent按關系模型上的角色名稱排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)

                  <tbody id='BNVIu'></tbody>

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

                • <tfoot id='BNVIu'></tfoot>

                  <legend id='BNVIu'><style id='BNVIu'><dir id='BNVIu'><q id='BNVIu'></q></dir></style></legend>
                        <bdo id='BNVIu'></bdo><ul id='BNVIu'></ul>
                        1. <i id='BNVIu'><tr id='BNVIu'><dt id='BNVIu'><q id='BNVIu'><span id='BNVIu'><b id='BNVIu'><form id='BNVIu'><ins id='BNVIu'></ins><ul id='BNVIu'></ul><sub id='BNVIu'></sub></form><legend id='BNVIu'></legend><bdo id='BNVIu'><pre id='BNVIu'><center id='BNVIu'></center></pre></bdo></b><th id='BNVIu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BNVIu'><tfoot id='BNVIu'></tfoot><dl id='BNVIu'><fieldset id='BNVIu'></fieldset></dl></div>
                          主站蜘蛛池模板: 国产永久免费 | 午夜精品福利视频 | 男女羞羞视频免费看 | 国产精品一区二区三区在线 | 成人国产精品久久 | 国产成人99久久亚洲综合精品 | 亚洲视频 欧美视频 | 超碰在线播 | 欧美日韩国产一区二区三区不卡 | 黄色一级大片在线观看 | 国产精品免费一区二区 | 欧美日韩在线免费观看 | 国产一区二区在线视频 | 午夜一区二区三区在线观看 | 91精品久久久久久久99 | 成人3d动漫一区二区三区91 | 操久久| 午夜在线视频 | 91社区在线观看播放 | 亚洲欧美日韩精品久久亚洲区 | 欧美性受xxxx| 欧美视频三区 | 成人av鲁丝片一区二区小说 | 日韩视频三区 | 久久久精品高清 | 欧美日韩理论 | 亚洲国产精品日本 | 欧美日韩国产综合在线 | 91看片网| 精品日韩 | 免费黄视频网站 | 日韩在线一区二区三区 | 91综合网 | 狠狠av | 久久伊人精品 | 欧美一区二区久久 | 在线亚洲一区 | 在线观看免费高清av | 国产精品久久久久久久久久久久久久 | 蜜桃在线一区二区三区 | 欧美一区在线看 |