<?php
namespace app\admin\model;
use think\Model;
use think\model\concern\SoftDelete;
/*
* 软删除步骤:
* 1.在表中添加一个字段: 删除时间(删除标志): delete_time
* 2.在模型类添加一个属性: $deleteTime = 'delete_time'
* 3.在模型中导入软删除的trait类库: SoftDelete
* 4.最新版本支持设置软删除的默认字段值
* */
class Staff extends Model
{
use SoftDelete;
//设置数据表的名称 = 'staff';
protected $table = 'staff';
//设置主键: 默认为id
protected $pk = 'staff_id';
//设置软删除时间的字段名
protected $defaultSoftDelete = 0;
//软删除:必须在模型中进行配置
public function softDelete(){
$res = StaffModel::withTrashed()->where('staff_id < 5')->select();
dump($res);
}
}
DROP TABLE IF EXISTS `staff`;
CREATE TABLE `staff` (
`staff_id` int(4) NOT NULL COMMENT '主键id',
`name` varchar(30) DEFAULT NULL COMMENT '姓名',
`sex` int(1) DEFAULT NULL COMMENT '性别0男1女',
`age` tinyint(4) DEFAULT NULL COMMENT '年龄',
`salary` int(6) DEFAULT NULL COMMENT '工资',
`delete_time` int(10) DEFAULT NULL,
PRIMARY KEY (`staff_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;