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

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

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

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

      <tfoot id='POhZM'></tfoot>

        Laravel Eloquent ORM 復制

        Laravel Eloquent ORM replicate(Laravel Eloquent ORM 復制)

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

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

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

                  問題描述

                  我在使用所有關系復制我的模型之一時遇到問題.

                  I have a problem with replicating one of my models with all the relationships.

                  數據庫結構如下:

                  Table1: products
                  id
                  name
                  
                  Table2: product_options
                  id
                  product_id
                  option
                  
                  Table3: categories
                  id
                  name
                  
                  Pivot table: product_categories
                  product_id
                  category_id
                  

                  關系是:

                  • product hasMany product_options
                  • 產品屬于多類別(通過 product_categories)

                  我想克隆一個具有所有關系的產品.目前這是我的代碼:

                  I would like to clone a product with all the relationships. Currently here is my code:

                  $product = Product::with('options')->find($id);
                  $new_product = $product->replicate();
                  $new_product->push();
                  foreach($product->options as $option){
                      $new_option = $option->replicate();
                      $new_option->product_id = $new_product->id;
                      $new_option->push();
                  }
                  

                  但這不起作用(關系未克隆 - 目前我只是嘗試克隆 product_options).

                  But this does not works (the relationships are not cloned - currently I just tried to clone the product_options).

                  推薦答案

                  這段代碼,對我有用:

                  $model = User::find($id);
                  
                  $model->load('invoices');
                  
                  $newModel = $model->replicate();
                  $newModel->push();
                  
                  foreach($model->getRelations() as $relation => $items){
                      foreach($items as $item){
                          unset($item->id);
                          $newModel->{$relation}()->create($item->toArray());
                      }
                  }
                  

                  從這里回答:克隆一個包含所有關系的 Eloquent 對象?

                  這個答案(同樣的問題),也很好用.

                  This answer (same question), also works fine too.

                  //copy attributes from original model
                  $newRecord = $original->replicate();
                  // Reset any fields needed to connect to another parent, etc
                  $newRecord->some_id = $otherParent->id;
                  //save model before you recreate relations (so it has an id)
                  $newRecord->push();
                  //reset relations on EXISTING MODEL (this way you can control which ones will be loaded
                  $original->relations = [];
                  //load relations on EXISTING MODEL
                  $original->load('somerelationship', 'anotherrelationship');
                  //re-sync the child relationships
                  $relations = $original->getRelations();
                  foreach ($relations as $relation) {
                      foreach ($relation as $relationRecord) {
                          $newRelationship = $relationRecord->replicate();
                          $newRelationship->some_parent_id = $newRecord->id;
                          $newRelationship->push();
                      }
                  }
                  

                  從這里:克隆一個包含所有關系的 Eloquent 對象?

                  根據我的經驗,該代碼適用于多對多關系.

                  The code works fine for many to many relationships in my experience.

                  這篇關于Laravel Eloquent ORM 復制的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='zTTWl'></bdo><ul id='zTTWl'></ul>
                    • <small id='zTTWl'></small><noframes id='zTTWl'>

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

                    • <tfoot id='zTTWl'></tfoot>

                          <tbody id='zTTWl'></tbody>

                          • 主站蜘蛛池模板: 91成人在线视频 | 日韩二 | 久久久久久久综合 | 日韩三极 | 国产精品毛片无码 | 在线播放中文字幕 | 日日摸夜夜添夜夜添特色大片 | 免费超碰| 国产一区二区三区在线免费 | 特黄色一级毛片 | 成人激情免费视频 | 密色视频| 国产精品久久一区 | 精品亚洲一区二区 | 另类一区 | 久久免费观看视频 | av片免费 | 精品久久影院 | 国产资源视频 | 高清18麻豆 | 亚洲视频在线免费观看 | 欧美综合一区二区三区 | 欧美一级在线观看 | 久久综合国产 | 91av入口| 91精品成人久久 | 欧美一级特黄aaa大片在线观看 | 国产精品污www一区二区三区 | 国产精品国产三级国产aⅴ入口 | 日韩国产一区二区三区 | 久久精品久久久久久 | 久久精品在线播放 | 国产亚洲精品精品国产亚洲综合 | 伊人一区| 毛片入口| 国产免费一区二区 | 国产精品一区二区三区四区 | 亚洲国产免费 | 免费av手机在线观看 | 久久久久久免费毛片精品 | 成人二区 |