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

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

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

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

        <bdo id='YYwGN'></bdo><ul id='YYwGN'></ul>
      1. <legend id='YYwGN'><style id='YYwGN'><dir id='YYwGN'><q id='YYwGN'></q></dir></style></legend>

      2. Laravel Eloquent 更新僅在進(jìn)行更改時(shí)

        Laravel Eloquent update just if changes have been made(Laravel Eloquent 更新僅在進(jìn)行更改時(shí))

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

              <legend id='WrBjc'><style id='WrBjc'><dir id='WrBjc'><q id='WrBjc'></q></dir></style></legend>

                  本文介紹了Laravel Eloquent 更新僅在進(jìn)行更改時(shí)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  如果對(duì)記錄進(jìn)行了更改,有沒(méi)有辦法使用 eloquent 模型更新 Laravel 中的記錄?我不希望任何用戶無(wú)緣無(wú)故地一遍又一遍地請(qǐng)求數(shù)據(jù)庫(kù),只需點(diǎn)擊按鈕即可保存更改.我有一個(gè) javascript 功能,可以根據(jù)頁(yè)面中的某些內(nèi)容是否已更改啟用和禁用保存按鈕,但我想知道是否可以確保在服務(wù)器上執(zhí)行此類功能邊也.我知道我可以自己完成它(意思是:不訴諸框架的內(nèi)部功能)只是通過(guò)檢查記錄是否有變化,但在這樣做之前,我想知道 Laravel eloquent 模型是否已經(jīng)處理好了這樣,我就不需要重新發(fā)明輪子了.

                  Is there any way to update a record in Laravel using eloquent models just if a change has been made to that record? I don't want any user requesting the database for no good reason over and over, just hitting the button to save changes. I have a javascript function that enables and disables the save button according with whether something has changed in the page, but I would like to know if it's possible to make sure to do this kind of feature on the server side too. I know I can accomplish it by myself (meaning: without appealing to an internal functionality of the framework) just by checking if the record has change, but before doing it that way, I would like to know if Laravel eloquent model already takes care of that, so I don't need to re-invent the wheel.

                  這是我用來(lái)更新記錄的方式:

                  This is the way I use to update a record:

                  $product = Product::find($data["id"]);
                  $product->title = $data["title"];
                  $product->description = $data["description"];
                  $product->price = $data["price"];
                  //etc (string values were previously sanitized for xss attacks)
                  $product->save();
                  

                  推薦答案

                  你已經(jīng)做到了!

                  save() 將檢查模型中的某些內(nèi)容是否已更改.如果沒(méi)有,它將不會(huì)運(yùn)行數(shù)據(jù)庫(kù)查詢.

                  save() will check if something in the model has changed. If it hasn't it won't run a db query.

                  下面是IlluminateDatabaseEloquentModel@performUpdate中相關(guān)部分的代碼:

                  Here's the relevant part of code in IlluminateDatabaseEloquentModel@performUpdate:

                  protected function performUpdate(Builder $query, array $options = [])
                  {
                      $dirty = $this->getDirty();
                  
                      if (count($dirty) > 0)
                      {
                          // runs update query
                      }
                  
                      return true;
                  }
                  

                  <小時(shí)>

                  getDirty() 方法只是將當(dāng)前屬性與創(chuàng)建模型時(shí)保存在 original 中的副本進(jìn)行比較.這是在 syncOriginal() 方法中完成的:


                  The getDirty() method simply compares the current attributes with a copy saved in original when the model is created. This is done in the syncOriginal() method:

                  public function __construct(array $attributes = array())
                  {
                      $this->bootIfNotBooted();
                  
                      $this->syncOriginal();
                  
                      $this->fill($attributes);
                  }
                  
                  public function syncOriginal()
                  {
                      $this->original = $this->attributes;
                  
                      return $this;
                  }
                  

                  <小時(shí)>

                  如果你想檢查模型是否臟,只需調(diào)用 isDirty():

                  if($product->isDirty()){
                      // changes have been made
                  }
                  

                  或者如果你想檢查某個(gè)屬性:

                  Or if you want to check a certain attribute:

                  if($product->isDirty('price')){
                      // price has changed
                  }
                  

                  這篇關(guān)于Laravel Eloquent 更新僅在進(jìn)行更改時(shí)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)程序)
                  <tfoot id='RtKUQ'></tfoot>

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

                          <bdo id='RtKUQ'></bdo><ul id='RtKUQ'></ul>
                            <tbody id='RtKUQ'></tbody>
                          • <small id='RtKUQ'></small><noframes id='RtKUQ'>

                          • <legend id='RtKUQ'><style id='RtKUQ'><dir id='RtKUQ'><q id='RtKUQ'></q></dir></style></legend>
                            主站蜘蛛池模板: 国产免费福利小视频 | 99riav国产一区二区三区 | 精品久久久久久久久久 | 久久久123 | va精品| 亚洲不卡一 | 国产精品一区在线 | 亚洲精品中文字幕 | 一级二级三级黄色 | 亚洲视频免费播放 | 亚洲激情第一页 | 狠狠干网站 | 久久一区二区免费视频 | 日韩中出| 精品亚洲一区二区 | 日韩精品一区在线 | 青青草这里只有精品 | 精品国产乱码久久久久久丨区2区 | 产真a观专区 | 情侣av| 国产黄色小视频 | 久久在线免费 | 成人精品国产一区二区4080 | 中文字幕在线观看av | 欧美一区二区三区免费在线观看 | 久久精品亚洲精品国产欧美 | 久久久久久久久99 | www.4hu影院 | 中文字幕在线观看视频网站 | 99视频精品 | 免费观看一级毛片 | 91在线视频网址 | 欧美阿v| 成人av观看| 中文字幕一区二区三区精彩视频 | 91九色网站| 亚洲欧洲国产视频 | 99久久精品国产一区二区三区 | 国产www成人| 欧美炮房| 日韩欧美视频在线 |