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

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

    <tfoot id='3KIZZ'></tfoot>

    <small id='3KIZZ'></small><noframes id='3KIZZ'>

      <bdo id='3KIZZ'></bdo><ul id='3KIZZ'></ul>
    <legend id='3KIZZ'><style id='3KIZZ'><dir id='3KIZZ'><q id='3KIZZ'></q></dir></style></legend>

        Laravel Eloquent 和多重連接

        Laravel Eloquent and Multiple Joins(Laravel Eloquent 和多重連接)

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

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

              1. <tfoot id='TnLzk'></tfoot>
                  本文介紹了Laravel Eloquent 和多重連接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我了解如何將 Eloquent 用于基本查詢和關系,但在根據多個表中的關系選擇信息時,我開始感到困惑.

                  I understand how to use Eloquent for basic queries and relationships, but I start getting confused when selecting information based on relationships in multiple tables.

                  例如,我可以使用查詢構建器從數據庫中獲取我需要的數據,如下所示:

                  For example, i can get the data I need from the database using the the query builder as follows:

                      $data['products'] = DB::table('product')
                      ->select('product.id', 'product.ref_num', 'productdetails.name')
                      ->join('productdetails', function($join)
                      {
                          $join->on('product.id', '=', 'productdetails.product_id')
                               ->where('productdetails.website_id', '=', '7');
                      })
                      ->leftJoin('product_category', function($join) use($submenu_id){
                          $join->on('product.id', '=', 'product_category.product_id')
                              ->where('product_category.category_id', '=', $submenu_id);
                      })
                      ->leftJoin('product_type', function($join) use($type_id){
                          $join->on('product.id', '=', 'product_type.product_id')
                              ->where('product_type.type_id', '=', $type_id);
                      })
                      ->get();
                  

                  基本上,我根據產品所屬的類別和產品類型從產品和產品詳細信息表中獲取數據;這些是由數據透視表 product_type 和 product_category 的內連接定義的.

                  Basically, i'm getting data from the product and productdetails tables based on which category the product is part of and what type of product it is; These are defined by inner joins to pivot tables product_type and product_category.

                  現在假設我正確設置了 eloquent 關系,我將如何在 Eloquent 中執行此操作?

                  Now assuming i have the eloquent relationships set up correctly, how would i go about doing this in Eloquent?

                  這里是 Eloquent 模型的相關部分

                  Here are the relevant parts of the Eloquent Models

                  產品

                  class Product extends Eloquent{
                  
                  public function productdetails()
                  {
                      return $this->hasMany('Productdetail');
                  
                  public function categories()
                  {
                      return $this->belongsToMany('Category', 'product_category', 'product_id', 'category_id');
                  }
                  
                  public function types()
                  {
                      return $this->belongsToMany('Producttype', 'product_type', 'product_id', 'type_id');
                  }
                  }
                  

                  產品詳情

                  class Productdetail extends Eloquent
                  {
                  
                  
                  public function product()
                  {
                      return $this->belongsTo('Product');
                  }
                  }
                  

                  產品類型

                  class ProductTypes extends Eloquent{
                  
                  
                  function products()
                  {
                      return $this->belongsToMany('products', 'product_id', 'type_id', 'product_id');
                  }
                  

                  類別

                  class Category extends Eloquent{
                  
                  public function products()
                  {
                      return $this->belongsToMany('product', 'product_category', 'category_id', 'product_id');
                  }
                  }
                  

                  提前致謝

                  推薦答案

                  假設你的關系是正確的并且相關的表名稱是:categories 和 types,這將完成這項工作:

                  Assuming your relations are correct and related table names are: categories and types, this will do the job:

                  Product::with('productdetails')
                      ->whereHas('categories', function ($query) use ($submenu_id) {
                            $query->where('categories.id', '=', $submenu_id);
                      })
                      ->whereHas('types', function ($query) use ($type_id) {
                            $query->where('types.id', $type_id); // side note: operator '=' is default, so can be ommited
                      })
                      ->get();
                  

                  它將運行 2 個查詢(第一個用于獲取合適的產品,第二個用于與它們相關的產品詳細信息)并返回 Eloquent Collection

                  It will run 2 queries ( first for getting appropriate products, second for product details related to them) and return Eloquent Collection

                  這篇關于Laravel 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 找不到驅動程序)

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

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

                            <i id='nLdM1'><tr id='nLdM1'><dt id='nLdM1'><q id='nLdM1'><span id='nLdM1'><b id='nLdM1'><form id='nLdM1'><ins id='nLdM1'></ins><ul id='nLdM1'></ul><sub id='nLdM1'></sub></form><legend id='nLdM1'></legend><bdo id='nLdM1'><pre id='nLdM1'><center id='nLdM1'></center></pre></bdo></b><th id='nLdM1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nLdM1'><tfoot id='nLdM1'></tfoot><dl id='nLdM1'><fieldset id='nLdM1'></fieldset></dl></div>
                            <legend id='nLdM1'><style id='nLdM1'><dir id='nLdM1'><q id='nLdM1'></q></dir></style></legend>
                            主站蜘蛛池模板: 天天射影院 | 国产一区二区在线91 | 欧美一区二区 | 中国一级毛片免费 | 亚洲高清在线观看 | 久草视频观看 | 毛片链接 | 超碰精品在线 | 久久国产精品一区二区三区 | 欧美激情va永久在线播放 | 91精品国产91久久久久久丝袜 | 黄视频免费 | 激情免费视频 | 一区二区三区播放 | 亚洲一区在线日韩在线深爱 | 999热精品视频 | 国产精品久久久久久久久久久免费看 | 亚洲精品www | 日本精品裸体写真集在线观看 | 中文字幕免费观看 | 国产97视频在线观看 | 日本精品在线一区 | 久久av一区 | 欧美黄色性生活视频 | 国产成人精品一区二 | 精品国产乱码久久久久久图片 | 国产国拍亚洲精品av | 日日夜夜精品视频 | 97精品超碰一区二区三区 | 99爱视频 | 久久国产区 | 51ⅴ精品国产91久久久久久 | 久久久久久综合 | 中文字幕一区二区三区乱码在线 | 欧美激情视频一区二区三区在线播放 | 久久久国产网站 | 久久精彩| 国产福利在线小视频 | 久久精品国产亚洲 | 亚洲成人一区 | 97精品久久 |