批改狀態(tài):合格
老師批語:
軟刪除步驟:
1、在表中添加一個字段:刪除時間(刪除標志):delete_time
2、在模型類中添加一個屬性:$deletetime = 'delete_time'
3、在模型中導入軟刪除的trait類庫:SoftDelete(think\model\concern\SoftDelete)
4、最新版本支持設(shè)置軟刪除的默認字段值:$defaultSoftDelete
<?php namespace app\index\controller; use think\Controller; use app\index\model\User as UserModel;//設(shè)置模型類的別名,防止沖突 class User extends Controller { public function softdelete() { UserModel::destroy(3); // 軟刪除的數(shù)據(jù)在普通查詢中不可見 // 如果想在查詢的時候看到已經(jīng)被刪除的結(jié)果,帶上方法 withTrashed() // 如果只看已經(jīng)刪除的,帶上方法onlyTrashed() } }
點擊 "運行實例" 按鈕查看在線實例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號