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

    • <bdo id='e0VUl'></bdo><ul id='e0VUl'></ul>
  • <small id='e0VUl'></small><noframes id='e0VUl'>

      <i id='e0VUl'><tr id='e0VUl'><dt id='e0VUl'><q id='e0VUl'><span id='e0VUl'><b id='e0VUl'><form id='e0VUl'><ins id='e0VUl'></ins><ul id='e0VUl'></ul><sub id='e0VUl'></sub></form><legend id='e0VUl'></legend><bdo id='e0VUl'><pre id='e0VUl'><center id='e0VUl'></center></pre></bdo></b><th id='e0VUl'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='e0VUl'><tfoot id='e0VUl'></tfoot><dl id='e0VUl'><fieldset id='e0VUl'></fieldset></dl></div>
    1. <tfoot id='e0VUl'></tfoot>
    2. <legend id='e0VUl'><style id='e0VUl'><dir id='e0VUl'><q id='e0VUl'></q></dir></style></legend>
      1. Laravel/Eloquent : hasManyThrough WHERE

        Laravel / Eloquent : hasManyThrough WHERE(Laravel/Eloquent : hasManyThrough WHERE)
        • <small id='MfYkJ'></small><noframes id='MfYkJ'>

            <tbody id='MfYkJ'></tbody>

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

            • <bdo id='MfYkJ'></bdo><ul id='MfYkJ'></ul>
                1. 本文介紹了Laravel/Eloquent : hasManyThrough WHERE的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在 Eloquent 的文檔中,據說我可以將所需關系的鍵傳遞給 hasManyThrough.

                  In the documentation of Eloquent it is said that I can pass the keys of a desired relationship to hasManyThrough.

                  假設我有名為 Country、User、Post 的模型.通過用戶模型,國家模型可能有許多帖子.也就是說,我可以直接調用:

                  Lets say I have Models named Country, User, Post. A Country model might have many Posts through a Users model. That said I simply could call:

                  $this->hasManyThrough('Post', 'User', 'country_id', 'user_id');
                  

                  到目前為止一切正常!但是我如何才能只為 id 為 3 的用戶獲取這些帖子?

                  有人可以幫忙嗎?

                  推薦答案

                  就這樣:

                  models: Country 有很多 User 有很多 Post

                  models: Country has many User has many Post

                  這允許我們在您的問題中使用 hasManyThrough :

                  This allows us to use hasManyThrough like in your question:

                  // Country model
                  public function posts()
                  {
                    return $this->hasManyThrough('Post', 'User', 'country_id', 'user_id');
                  }
                  

                  您想獲取此關系的給定用戶的帖子,因此:

                  You want to get posts of a given user for this relation, so:

                  $country = Country::first();
                  $country->load(['posts' => function ($q) {
                    $q->where('user_id', '=', 3);
                  }]);
                  // or
                  $country->load(['posts' => function ($q) {
                    $q->has('user', function ($q) {
                      $q->where('users.id', '=', 3);
                    });
                  })
                  
                  $country->posts; // collection of posts related to user with id 3
                  

                  <小時>

                  但是如果你改用它,它會更容易、更易讀和更有說服力:(因為當您在尋找 id 為 3 的用戶的帖子時,它與國家無關)


                  BUT it will be easier, more readable and more eloquent if you use this instead: (since it has nothing to do with country when you are looking for the posts of user with id 3)

                  // User model
                  public function posts()
                  {
                    return $this->hasMany('Post');
                  }
                  
                  // then
                  $user = User::find(3);
                  // lazy load
                  $user->load('posts');
                  // or use dynamic property
                  $user->posts; // it will load the posts automatically
                  // or eager load
                  $user = User::with('posts')->find(3);
                  
                  $user->posts; // collection of posts for given user
                  

                  總結一下:hasManyThrough是一種直接獲取嵌套關系的方法,即.給定國家/地區的所有帖子,而不是搜索特定的 through 模型.

                  To sum up: hasManyThrough is a way to get nested relation directly, ie. all the posts for given country, but rather not to search for specific through model.

                  這篇關于Laravel/Eloquent : hasManyThrough WHERE的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)

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

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

                      <tfoot id='bqCk7'></tfoot>
                          <tbody id='bqCk7'></tbody>

                          • <bdo id='bqCk7'></bdo><ul id='bqCk7'></ul>
                          • 主站蜘蛛池模板: 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 蜜桃一区二区三区在线 | 亚洲顶级毛片 | 久久www免费人成看片高清 | 欧美xxxx黑人又粗又长 | 亚洲欧美日韩久久久 | 波多野结衣一区二区 | 人人看人人射 | 久久久久久国产精品 | 91久久精品一区 | 日韩精品在线播放 | 一级久久久久久 | www.99热.com| 中国xxxx性xxxx产国 | 成人免费观看男女羞羞视频 | 一区二区三区视频在线观看 | av中文在线 | 国产亚洲人成a在线v网站 | 一区二区三区四区电影视频在线观看 | 国产精品久久777777 | 二区不卡| 天天综合91 | 男女国产网站 | aaa级片| 国产片一区二区三区 | 国产精品久久av | 精品国产一区二区三区av片 | 欧产日产国产精品99 | 亚洲欧洲一区二区 | 五月香婷婷 | 丁香五月缴情综合网 | 久久久久久久电影 | 亚洲综合在线一区 | www.日韩系列 | 亚洲在线一区二区三区 | 精品一区二区三区视频在线观看 | 国产欧美日韩综合精品一区二区 | 9191在线观看 | 91精品亚洲| 国产中文字幕网 | 成人av鲁丝片一区二区小说 |