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

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

        <bdo id='gz7Oa'></bdo><ul id='gz7Oa'></ul>
    1. <legend id='gz7Oa'><style id='gz7Oa'><dir id='gz7Oa'><q id='gz7Oa'></q></dir></style></legend><tfoot id='gz7Oa'></tfoot>

    2. <small id='gz7Oa'></small><noframes id='gz7Oa'>

      Laravel eloquent 獲取所有記錄,其中包含多對多關系

      Laravel eloquent get all records wherehas all ids in many to many relation(Laravel eloquent 獲取所有記錄,其中包含多對多關系中的所有 id)
        <tbody id='rbZeq'></tbody>
    3. <i id='rbZeq'><tr id='rbZeq'><dt id='rbZeq'><q id='rbZeq'><span id='rbZeq'><b id='rbZeq'><form id='rbZeq'><ins id='rbZeq'></ins><ul id='rbZeq'></ul><sub id='rbZeq'></sub></form><legend id='rbZeq'></legend><bdo id='rbZeq'><pre id='rbZeq'><center id='rbZeq'></center></pre></bdo></b><th id='rbZeq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rbZeq'><tfoot id='rbZeq'></tfoot><dl id='rbZeq'><fieldset id='rbZeq'></fieldset></dl></div>
        <tfoot id='rbZeq'></tfoot>

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

            <legend id='rbZeq'><style id='rbZeq'><dir id='rbZeq'><q id='rbZeq'></q></dir></style></legend>
              • <bdo id='rbZeq'></bdo><ul id='rbZeq'></ul>
                本文介紹了Laravel eloquent 獲取所有記錄,其中包含多對多關系中的所有 id的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個 Posts 表,它有三個字段 idtitledescription.

                I have a Posts table it has three fields id, title, description.

                我的發布模型

                class Post extends Model
                {
                    use SoftDeletes;
                
                    protected $fillable = ['title', 'description'];
                
                    public function tags()
                    {
                        return $this->belongsToMany(Tag::class, 'post_tag');
                    }
                }
                

                我的標簽模型

                class Tag extends Model
                {
                    use SoftDeletes;
                
                    protected $fillable = ['name'];
                
                    public function posts()
                    {
                        return $this->belongsToMany(Post::class, 'post_tag');
                    }
                }
                

                現在我想獲得帖子&在我有標簽過濾器的地方分頁,例如我有兩個標簽 animals &news id 1 &2.現在我想獲取所有帶有標簽 1 & 的帖子2 &分頁.這是我試過的

                Now I want to get posts & paginate where I have a tag filter e.g I have two tags animals & news which has id 1 & 2. Now I want to get all posts which has tag 1 & 2 & paginate. Here is what I tried

                        Post:: with('tags')->whereHas('tags', function($q) {
                            $q->whereIn('id', [1, 2]);
                        })->paginate();
                

                但在這里,我是 whereIn,它返回的帖子有標簽 12both.但我想要同時具有標簽 ID 1 和標簽的帖子2.

                But here as I am whereIn it returns posts has tags 1 or 2 or both. But I want post who has both tag id 1 & 2.

                我使用的是 Laravel 5.2.

                推薦答案

                我一直在尋找相同的東西并受到 this stackoverflow MySQL answer,我已經結束了這個

                I have been looking for the same thing and inspired by this stackoverflow MySQL answer, I have ended up with this

                代碼:

                Post:: with('tags')->whereHas('tags', function($q) {
                    $idList = [1,2];
                    $q->whereIn('id', $idList)
                      ->havingRaw('COUNT(id) = ?', [count($idList)])
                })->paginate();
                

                因為我想我可能會在一些地方使用它,所以我已經把它變成了一個特性,你可以在這里查看.如果您在 Post 類中包含 trait,您可以像下面這樣使用.

                Because I think I might use it in a few places I have made it into a trait which you can view here. Which if you included the trait in your Post class you could use like the following.

                代碼:

                Post::with('tags')->whereHasRelationIds('tags', [1,2])->paginate();
                

                這篇關于Laravel eloquent 獲取所有記錄,其中包含多對多關系中的所有 id的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                • <bdo id='yDePX'></bdo><ul id='yDePX'></ul>
                    <tbody id='yDePX'></tbody>

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

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

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

                          主站蜘蛛池模板: 国产精品一区久久久 | 综合一区| 亚洲精品中文在线 | 亚洲国产二区 | 欧美aⅴ在线观看 | 亚洲精品成人av久久 | 精品久久久久久亚洲精品 | 精品在线99 | 亚洲精品一| 四虎影院在线观看免费视频 | 伊人伊成久久人综合网站 | 亚洲精品久久久一区二区三区 | 日韩国产中文字幕 | 九一视频在线播放 | 亚洲欧美日韩精品久久亚洲区 | 视频1区 | 精品久久久久久亚洲国产800 | 久久五月婷| 狠狠操狠狠操 | 欧美日韩高清在线一区 | 成人在线视频网 | 欧美久久不卡 | 超碰97人人人人人蜜桃 | 国产四区 | 少妇精品久久久久久久久久 | 在线中文字幕视频 | 婷婷五月色综合香五月 | 国产成人精品免费视频大全最热 | 国产不卡视频在线 | 精品综合 | 欧美日本亚洲 | 久久99精品久久久久久青青日本 | 一区二区三区av | 日本精品一区二区三区在线观看视频 | 日韩精品视频一区二区三区 | 国产一区 | 91精品在线看 | 久久精品视频一区二区三区 | 久久久久久久电影 | 99免费精品视频 | 久久国产精品-久久精品 |