久久久久久久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 - 附加與同步的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  解決方案

                  attach():

                  • 在處理多對多關(guān)系時(shí)插入相關(guān)模型
                  • 不需要數(shù)組參數(shù)

                  示例:

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

                  sync():

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

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

                  示例:

                  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
                  
                  

                  這篇關(guān)于Laravel Eloquent - 附加與同步的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                    <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>
                            主站蜘蛛池模板: 亚洲毛片在线 | 欧美一区二区三区 | 一色一黄视频 | 国产免费va | 亚洲a毛片 | 日本成人中文字幕 | 美女一级毛片 | 欧美精品一区三区 | 视频一区二区国产 | 亚洲狠狠丁香婷婷综合久久久 | 亚洲日本视频 | 欧美三级电影在线播放 | 亚洲三级在线观看 | 91秦先生艺校小琴 | 中文字幕精品一区二区三区精品 | 久久av一区 | 狠狠爱一区二区三区 | 日韩一级欧美一级 | 亚洲综合激情 | 国产免费一级一级 | 国产成人精品久久二区二区 | 国产精品国色综合久久 | 中文字幕视频一区 | 国产福利视频在线观看 | av黄色国产 | 中国美女一级黄色片 | 欧美a区| 日韩av成人| 日韩在线免费 | 国产精品久久国产精品99 | 国产精品久久久 | 国产视频第一页 | 天天爱爱网 | 中文字幕在线一区 | 国产在线精品一区 | 国产精彩视频 | 国产精品1区2区3区 国产在线观看一区 | 一色一黄视频 | 久久在线 | 91精品国产自产在线老师啪 | 美女网站视频免费黄 |