批改状态:合格
老师批语:
软删除步骤:
1、在表中添加一个字段:删除时间(删除标志):delete_time
2、在模型类中添加一个属性:$deletetime = 'delete_time'
3、在模型中导入软删除的trait类库:SoftDelete(think\model\concern\SoftDelete)
4、最新版本支持设置软删除的默认字段值:$defaultSoftDelete
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User as UserModel;//设置模型类的别名,防止冲突
class User extends Controller
{
public function softdelete()
{
UserModel::destroy(3);
// 软删除的数据在普通查询中不可见
// 如果想在查询的时候看到已经被删除的结果,带上方法 withTrashed()
// 如果只看已经删除的,带上方法onlyTrashed()
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号