久久久久久久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按關(guān)系模型上的角色名稱排序

      Laravel eloquent sort by role name on relationship model(Laravel eloquent按關(guān)系模型上的角色名稱排序)
        <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按關(guān)系模型上的角色名稱排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我遇到了一個問題,我必須根據(jù)模型的關(guān)系數(shù)據(jù)對模型集合進(jìn)行排序/排序.

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

                我的設(shè)置如下:

                型號:UserTeamTeamUserRole

                TeamUser 模型是一個數(shù)據(jù)透視模型/表(包含 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 對團(tuán)隊中的用戶進(jìn)行排序,我該怎么做?我正在談?wù)?Team 模型中的 users() 關(guān)系(請參閱代碼示例的進(jìn)一步內(nèi)容).一些用戶具有 team-leader 角色,大多數(shù)用戶具有 team-seller 角色.我試過做一個普通的 ..->sortBy('role.name') 但這似乎不起作用.如果有人可以幫助我,請?zhí)崆爸轮x.

                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();
                }
                

                推薦答案

                如果要根據(jù)嵌套關(guān)系列對結(jié)果進(jìn)行排序,則必須使用連接鏈:

                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();
                

                我試過了,效果很好.

                請注意,如果您想按多列排序,您可以根據(jù)需要添加 '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
                

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

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

                相關(guān)文檔推薦

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

                  <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>
                          主站蜘蛛池模板: 久久区二区 | 狠狠骚| 午夜精品久久久久久久星辰影院 | 一区在线视频 | av网站在线免费观看 | 欧美精品一区二区三区在线四季 | 日韩毛片免费视频 | 九九精品在线 | 亚洲精品一区二区在线观看 | 蜜桃在线视频 | 欧美一区2区三区4区公司 | 一二三四在线视频观看社区 | 男女免费视频网站 | 久久久网 | 国产福利91精品一区二区三区 | 欧美一区二区三区 | 国产欧美精品一区二区色综合朱莉 | 亚洲精品乱码久久久久久蜜桃91 | 99久久精品国产一区二区三区 | 久久亚洲天堂 | 亚洲精品视频播放 | 中国免费黄色片 | 农夫在线精品视频免费观看 | 99亚洲| 精品视频一二区 | 日韩成人在线一区 | 91视频网 | 亚洲精品久久久久久久久久久 | 精品久久久久一区二区国产 | 久久久久久国产精品免费免费 | 中文字幕免费 | 欧美精品久久久久久 | 亚洲成人一区二区三区 | 亚洲第一av | 国产日产久久高清欧美一区 | 国产精品福利一区二区三区 | 欧美1区2区 | 国产一伦一伦一伦 | 欧美男人的天堂 | 国产亚洲成av人在线观看导航 | 999热在线视频 |