<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 軟刪除 在實際項目中,對數據頻繁使用刪除操作會導致性能問題,軟刪除的作用就是把數據加上刪除標記,而不是真正的刪除,同時也便于需要的時候進行數據的恢復。 要使用軟刪除功能,需要引入`SoftDelete` trait,例如`User`模型按照下面的定義就可以使用軟刪除功能: ~~~ <?php namespace app\model; use think\Model; use think\model\concern\SoftDelete; class User extends Model { use SoftDelete; protected $deleteTime = 'delete_time'; } ~~~ `deleteTime`屬性用于定義你的軟刪除標記字段,`ThinkPHP`的軟刪除功能使用時間戳類型(數據表默認值為`Null`),用于記錄數據的刪除時間。 可以支持`defaultSoftDelete`屬性來定義軟刪除字段的默認值,在此之前的版本,軟刪除字段的默認值必須為`null`。 ~~~ <?php namespace app\model; use think\Model; use think\model\concern\SoftDelete; class User extends Model { use SoftDelete; protected $deleteTime = 'delete_time'; protected $defaultSoftDelete = 0; } ~~~ > 可以用類型轉換指定軟刪除字段的類型,建議數據表的所有時間字段統一一種類型。 定義好模型后,我們就可以使用: ~~~ // 軟刪除 User::destroy(1); // 真實刪除 User::destroy(1,true); $user = User::find(1); // 軟刪除 $user->delete(); // 真實刪除 $user->force()->delete(); ~~~ 默認情況下查詢的數據不包含軟刪除數據,如果需要包含軟刪除的數據,可以使用下面的方式查詢: ~~~ User::withTrashed()->find(); User::withTrashed()->select(); ~~~ 如果僅僅需要查詢軟刪除的數據,可以使用: ~~~ User::onlyTrashed()->find(); User::onlyTrashed()->select(); ~~~ 恢復被軟刪除的數據 ~~~php $user = User::onlyTrashed()->find(1); $user->restore(); ~~~ >[danger] 軟刪除的刪除操作僅對模型的刪除方法有效,如果直接使用數據庫的刪除方法則無效,例如下面的方式無效。 ~~~ $user = new User; $user->where('id',1)->delete(); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看