Blogger Information
Blog 48
fans 3
comment 1
visits 37426
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
软删除步骤及实例——2018年5月24日
JackBlog
Original
818 people have browsed it

软删除步骤:

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()
	}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post