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

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

        <bdo id='gEaxa'></bdo><ul id='gEaxa'></ul>
    2. <tfoot id='gEaxa'></tfoot>

    3. <legend id='gEaxa'><style id='gEaxa'><dir id='gEaxa'><q id='gEaxa'></q></dir></style></legend>
      1. Laravel Eloquent - 附加與同步

        Laravel Eloquent - Attach vs Sync(Laravel Eloquent - 附加與同步)
      2. <i id='WTyJa'><tr id='WTyJa'><dt id='WTyJa'><q id='WTyJa'><span id='WTyJa'><b id='WTyJa'><form id='WTyJa'><ins id='WTyJa'></ins><ul id='WTyJa'></ul><sub id='WTyJa'></sub></form><legend id='WTyJa'></legend><bdo id='WTyJa'><pre id='WTyJa'><center id='WTyJa'></center></pre></bdo></b><th id='WTyJa'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WTyJa'><tfoot id='WTyJa'></tfoot><dl id='WTyJa'><fieldset id='WTyJa'></fieldset></dl></div>
          <legend id='WTyJa'><style id='WTyJa'><dir id='WTyJa'><q id='WTyJa'></q></dir></style></legend>
              <tbody id='WTyJa'></tbody>
          1. <small id='WTyJa'></small><noframes id='WTyJa'>

            • <tfoot id='WTyJa'></tfoot>
                  <bdo id='WTyJa'></bdo><ul id='WTyJa'></ul>
                  本文介紹了Laravel Eloquent - 附加與同步的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  Laravel 4 的 Eloquent ORM 中的 attach()sync() 有什么區別?我試圖環顧四周,但找不到任何東西!

                  解決方案

                  attach():

                  • 在處理多對多關系時插入相關模型
                  • 不需要數組參數

                  示例:

                  $user = User::find(1);$user->roles()->attach(1);

                  sync():

                  attach()方法類似,sync()方法用于附加相關模型.但是,主要區別在于:

                  • sync() 接受要放在數據透視表上的 ID 數組
                  • 其次,最重要的,如果數組中不存在模型,同步方法會從數據透視表中刪除數據,并只將新項目插入數據透視表.

                  示例:

                  user_role

                  <前>id user_id role_id1 12 12 12 53 12 2

                  $user = User::find(12);$user->roles()->sync(array(1, 2, 3));

                  以上操作將刪除:

                  <前>id user_id role_id2 12 5

                  然后將 role_id 3 插入到表中.

                  user_role 表

                  <前>id user_id role_id1 12 13 12 24 12 3

                  What is the difference between attach() and sync() in Laravel 4's Eloquent ORM? I've tried to look around but couldn't find anything!

                  解決方案

                  attach():

                  • Insert related models when working with many-to-many relations
                  • No array parameter is expected

                  Example:

                  $user = User::find(1);
                  $user->roles()->attach(1);
                  

                  sync():

                  Similar to the attach() method, the sync() method is used to attach related models. However, the main differences are:

                  • sync() accepts an array of IDs to place on the pivot table
                  • Secondly, most important, the sync method will delete the data from the pivot table if the model does not exist in the array, and insert only the new items to the pivot table.

                  Example:

                  user_role

                  id  user_id role_id
                  1    12       1
                  2    12       5
                  3    12       2
                  

                  $user = User::find(12);
                  $user->roles()->sync(array(1, 2, 3));
                  

                  The above operation will delete:

                  id  user_id role_id
                  2    12       5
                  
                  

                  And insert role_id 3 to the table.

                  user_role table

                  id  user_id role_id
                  1    12       1
                  3    12       2
                  4    12       3
                  
                  

                  這篇關于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 找不到驅動程序)
                    <bdo id='q7rxw'></bdo><ul id='q7rxw'></ul>

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

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

                              <tbody id='q7rxw'></tbody>
                            主站蜘蛛池模板: 国产精品1区2区3区 中文字幕一区二区三区四区 | 午夜伦4480yy私人影院 | 毛片一区二区三区 | 国产欧美一区二区三区久久人妖 | 亚洲成人在线视频播放 | 一区二区中文 | 国产欧美精品区一区二区三区 | 久草新在线| 中文字幕的av | 久久成人精品视频 | 精品国产一区二区三区av片 | 一区二区三区四区在线 | 中文字幕亚洲精品 | 欧美中文一区 | 国偷自产av一区二区三区 | 二区亚洲 | 自拍 亚洲 欧美 老师 丝袜 | 99视频在线免费观看 | 久久一区精品 | 久久综合久久综合久久 | 精品一区二区三区免费视频 | 日韩欧美国产精品一区二区三区 | 伊人激情网 | 国产精品美女久久久久aⅴ国产馆 | 久久精品无码一区二区三区 | 国产日韩一区 | 成人在线视频网址 | 精品国产三级 | 日韩在线播放第一页 | 台湾佬成人网 | 青青久久av北条麻妃海外网 | 成人毛片视频在线播放 | 国产精品免费视频一区 | 一区二区三区中文字幕 | 成人在线免费电影 | 久久综合成人精品亚洲另类欧美 | 国产精品久久久久久久久久免费 | 精品久久久久久久久久 | 在线激情视频 | 亚洲精品视频二区 | 亚洲成人中文字幕 |