thinkphp5.1实例化模型操作delete 和destroy 方法 久久不能得到的东西
2022-07-28 14:14:58
172
{{single.collect_count}}

thinkphp5.1实例化模型操作delete 和destroy 方法

经过查看手册
在这里插入图片描述终于找到了这个bug 原来手册里面已经说明了,可惜没有仔细看
经过查找资料还是有方法可以解决问题 ## 闭包
像下边这种是不生效的。

User::where('field1','op1')->where('field2','op2')->delete();

下边这样才生效。
多种where条件组合的话,需要使用destroy 方法,或者查出来主键,直接给到destroy方法里删除

 RemindRecord::destroy(function ($query) use ($id){$query->where('loop_id',$id)->where('is_done',0);});

模型删除,尤其是软删除。要用destroy 方法,能指定主键最好指定主键值删除,条件删除的话必须使用闭包传入where 条件。
受到的启发

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}