thinkphp soft delete

Data is achieved by softdelete trait in thinkphp5 in soft-deleted. Need to introduce the model in use in the definition softdelete trait, and add protected $ deleteTime = database fields, can achieve data soft deletion. After the soft delete, view the database table by sql found that the time stamps added content in the appropriate fields.

The benefits of using soft-deleted at execute the query, the system will be filtered off soft-deleted data is automatically added deleteTime is null in sql statement.

Often developers, we will identify similar status field to record data if available, soft deleted is judged by isnul property deletetime, if we do not have agreement, commonly known as soft data to be deleted, so many people develop problems arise, because "" delete method to delete only soft model of effective, if used directly delete database method is invalid, such as invalid the following manner (will not do anything). "

$user = new User;
$user->where('id',1)->delete();
这句在tp5.1的手册中添加的,5.0手册没有这句
因为使用了->where就是使用了Db类,所以这个删除不会进行任何操作
delete method thinkphp no conditions of default is not to delete the soft delete destory comes through the primary key to delete, so I ended up using bulk delete update, modify the state at the same time of deletion.
The method is not genius, just record a pit encountered, Great God can guide, open-minded people do not blame

Guess you like

Origin www.cnblogs.com/widgetbox/p/12127882.html