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

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

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

        <bdo id='lYAKN'></bdo><ul id='lYAKN'></ul>
      <tfoot id='lYAKN'></tfoot>
    1. <legend id='lYAKN'><style id='lYAKN'><dir id='lYAKN'><q id='lYAKN'></q></dir></style></legend>
    2. 查詢關系 Eloquent

      Query relationship Eloquent(查詢關系 Eloquent)

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

          <tbody id='wrG2L'></tbody>

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

                <bdo id='wrG2L'></bdo><ul id='wrG2L'></ul>
                <legend id='wrG2L'><style id='wrG2L'><dir id='wrG2L'><q id='wrG2L'></q></dir></style></legend>
              • 本文介紹了查詢關系 Eloquent的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有 News 模型,而且 News 有很多評論,所以我在 News 模型中做了這個:

                I have News model, and News has many comments, so I did this in News model:

                public function comments(){
                    $this->hasMany('Comment', 'news_id');
                }
                

                但是我在 comments 表中也有字段 trashed,我只想選擇沒有被刪除的評論.所以 廢棄了 <>1.所以我想知道有沒有辦法做這樣的事情:

                But I also have field trashed in comments table, and I only want to select comments that are not trashed. So trashed <> 1. So I wonder is there a way to do something like this:

                $news = News::find(123);
                $news->comments->where('trashed', '<>', 1); //some sort of pseudo-code
                

                有沒有辦法使用上述方法,或者我應該寫這樣的東西:

                Is there a way to use above method or should I just write something like this:

                $comments = Comment::where('trashed', '<>', 1)
                    ->where('news_id', '=', $news->id)
                    ->get();
                

                推薦答案

                這些都適合你,選擇你最喜歡的:

                Any of these should work for you, pick the one you like the most:

                1. 急切加載.

                1. Eager-loading.

                $comments = News::find(123)->with(['comments' => function ($query) {
                    $query->where('trashed', '<>', 1);
                }])->get();
                

                您可以通過 use($param) 方法將參數注入查詢函數,這允許您在運行時使用動態查詢值.

                You can inject the parameter to query function by use($param) method, that allows you to use dynemic query value at runtime.

                延遲加載

                $news = News::find(123);
                $comments = $news->comments()->where('trashed', '<>', 1)->get();
                

                <小時>

                不過,我忍不住注意到,您可能想做的是處理軟刪除,而 Laravel 有內置功能可以幫助您:http://laravel.com/docs/eloquent#soft-deleting

                這篇關于查詢關系 Eloquent的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                <i id='VHGuR'><tr id='VHGuR'><dt id='VHGuR'><q id='VHGuR'><span id='VHGuR'><b id='VHGuR'><form id='VHGuR'><ins id='VHGuR'></ins><ul id='VHGuR'></ul><sub id='VHGuR'></sub></form><legend id='VHGuR'></legend><bdo id='VHGuR'><pre id='VHGuR'><center id='VHGuR'></center></pre></bdo></b><th id='VHGuR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VHGuR'><tfoot id='VHGuR'></tfoot><dl id='VHGuR'><fieldset id='VHGuR'></fieldset></dl></div>

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

                      • <bdo id='VHGuR'></bdo><ul id='VHGuR'></ul>

                          <tbody id='VHGuR'></tbody>
                      • <tfoot id='VHGuR'></tfoot>

                          <legend id='VHGuR'><style id='VHGuR'><dir id='VHGuR'><q id='VHGuR'></q></dir></style></legend>
                          主站蜘蛛池模板: 中文字幕的av | 免费欧美视频 | 免费国产一区 | 日韩中文一区 | 国产aⅴ | 99色播| 亚洲精品福利视频 | 视频1区| www.99热.com| 精品欧美一区二区三区久久久 | 91精品国产91久久久久久最新 | 热久久999| 久久久久成人精品亚洲国产 | 欧美精品久久 | 国产精品视频一区二区三区 | 国产日韩一区 | 91精品国产91久久久久游泳池 | 香蕉久久久 | 黄在线免费观看 | 精品一区二区三区在线观看国产 | 一级黄色片一级黄色片 | 丁香综合 | 黄频视频| 久久综合狠狠综合久久综合88 | 日韩欧美久久 | 欧美一区二区三区 | 欧美乱做爰xxxⅹ久久久 | 丝袜美腿一区 | 亚洲第一视频网 | 亚洲福利在线观看 | 狠狠操在线 | 成人久久久 | 91视频在线 | 精品国产欧美一区二区 | 欧美一级欧美三级在线观看 | 91免费版在线观看 | 97av在线| 久久99精品国产 | 日韩激情在线 | 综合色播 | 天堂资源|