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

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

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

        <bdo id='Ho0we'></bdo><ul id='Ho0we'></ul>

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

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

      如何在 Laravel 中使用 Eloquent 最后對(duì) NULL 值進(jìn)行排

      How to sort NULL values last using Eloquent in Laravel(如何在 Laravel 中使用 Eloquent 最后對(duì) NULL 值進(jìn)行排序)

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

              • 本文介紹了如何在 Laravel 中使用 Eloquent 最后對(duì) NULL 值進(jìn)行排序的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問題描述

                我的員工和組表之間存在多對(duì)多關(guān)系.我已經(jīng)創(chuàng)建了數(shù)據(jù)透視表,并且一切正常.但是,我的員工表上有一個(gè) sortOrder 列,用于確定它們的顯示順序.sortOrder 列中值為 1 的員工應(yīng)該排在第一位,值為 2 的員工排在第二位,依此類推.(如果按降序排序,則向后) sortOrder 列是一個(gè)允許空值的整數(shù)列.

                I've got a many to many relationship between my employees and groups table. I've created the pivot table, and all is working correctly with that. However, I've got a sortOrder column on my employees table that I use to determine the order in which they display. Employee with a value of 1 in the sortOrder column should be first, value of 2 should be second, so on. (Or backwards if sorted descending) The sortOrder column is a integer column that allows null values.

                我已經(jīng)設(shè)置了我的組模型來(lái)按排序列對(duì)員工進(jìn)行排序,但是我遇到了一個(gè)問題.始終首先顯示空值.我已經(jīng)嘗試使用 ISNULL 和類似的 SQL 方法來(lái)代替使用的常規(guī)asc"或desc",但我只得到一個(gè)錯(cuò)誤.

                I've set up my group model to sort the employees by the sort column, but I've run into a problem. The null values always are displayed first. I've tried using ISNULL and similar SQL methods in place of the regular "asc" or "desc" used, but I only get an error.

                這是我的組模型中的代碼:

                Here's the code in my Group model:

                class Group extends Eloquent {
                
                public function employees()
                    {
                        return $this->belongsToMany("Employee")->orderBy('sortOrder', 'asc');
                    }
                }
                

                這是我在控制器中用來(lái)訪問我的模型的內(nèi)容:

                And here's what I use in the controller to access my model:

                $board = Group::find(6)->employees;
                

                Laravel 中最后對(duì) NULL 值進(jìn)行排序的技巧是什么?

                What's the trick in Laravel to sorting NULL values last?

                推薦答案

                Laravel 沒有考慮 ISNULL 方法,但是你可以將它作為原始查詢傳入并仍然使用它因?yàn)樗?IF 語(yǔ)句更有效,并且如果您的員工人數(shù)超過(guò) 1000000 人(已接受的答案),結(jié)果將保持不變,如下所示:

                Laravel does not take into consideration the ISNULL method however, you can pass it in as a raw query and still make use of it as it's more efficient than IF statements and the results will stay the same if you ever go beyond 1000000 employees (accepted answer), like so:

                public function employees()
                {
                    return $this->hasMany('Employee')
                                ->orderBy(DB::raw('ISNULL(sortOrder), sortOrder'), 'ASC');
                }
                

                更新:您還可以使用 orderByRaw() 方法:

                Update: You can also use the orderByRaw() method:

                public function employees()
                {
                    return $this->hasMany('Employee')
                                ->orderByRaw('ISNULL(sortOrder), sortOrder ASC');
                }
                

                這篇關(guān)于如何在 Laravel 中使用 Eloquent 最后對(duì) NULL 值進(jìn)行排序的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)

                  <tbody id='u0syl'></tbody>
                    <bdo id='u0syl'></bdo><ul id='u0syl'></ul>
                  • <tfoot id='u0syl'></tfoot>

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

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

                        1. <i id='u0syl'><tr id='u0syl'><dt id='u0syl'><q id='u0syl'><span id='u0syl'><b id='u0syl'><form id='u0syl'><ins id='u0syl'></ins><ul id='u0syl'></ul><sub id='u0syl'></sub></form><legend id='u0syl'></legend><bdo id='u0syl'><pre id='u0syl'><center id='u0syl'></center></pre></bdo></b><th id='u0syl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='u0syl'><tfoot id='u0syl'></tfoot><dl id='u0syl'><fieldset id='u0syl'></fieldset></dl></div>
                        2. 主站蜘蛛池模板: 欧美日韩免费视频 | 久久乐国产精品 | 精品国产一区二区三区成人影院 | www.干| 亚洲毛片一区二区 | 久久久久久久久综合 | 成年人在线视频 | www.性色 | 欧美日韩视频 | a级毛片毛片免费观看久潮喷 | 亚洲色图图片 | 久久合久久| 日本韩国欧美在线观看 | 午夜电影网| 国产一级在线 | 午夜精品久久久久久久久久久久久 | 韩日一区二区 | 99精品久久久 | 羞羞午夜| 在线观看亚洲精品 | 日本三级网址 | 狠狠爱免费视频 | 久久综合色综合 | 午夜性色a√在线视频观看9 | 亚洲精品久久久一区二区三区 | 99av成人精品国语自产拍 | 九九亚洲| 国产高清免费视频 | 少妇一级淫片免费放播放 | 亚洲国产欧美日韩 | 欧美精品免费观看二区 | 噜噜噜噜狠狠狠7777视频 | 免费看国产片在线观看 | 国产精品亚洲第一区在线暖暖韩国 | 成人网址在线观看 | 天天干天天爱天天爽 | 日本久久久一区二区三区 | 亚洲社区在线 | 秋霞精品 | 亚洲理论在线观看电影 | 综合网中文字幕 |