如何检查行是否在雄辩中被软删除? [英] How to check if row is soft-deleted in Eloquent?

查看:75
本文介绍了如何检查行是否在雄辩中被软删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Laravel 5.1中,有一种很好的方法来检查是否雄辩地删除了雄辩的模型对象?我不是在谈论选择数据,而是一旦有了对象,例如Thing::withTrashed()->find($id)

In Laravel 5.1 is there a nice way to check if an eloquent model object has been soft-deleted? I'm not talking about selecting data but once I have the object e.g. Thing::withTrashed()->find($id)

到目前为止,我唯一能看到的就是

So far the only way I can see is

if ($thing->deleted_at !== null) { ... }

我在API中没有看到任何相关方法

I do not see any relevant method in the API that would allow for example

if ($thing->isDeleted()) { ... }

推荐答案

我刚刚意识到我在寻找错误的API. Model类没有这个,但是 SoftDelete特性我的模型使用的是trashed()方法.

Just realised I was looking in the wrong API. The Model class doesn't have this, but the SoftDelete trait that my models use has a trashed() method.

所以我可以写

if ($thing->trashed()) { ... }

这篇关于如何检查行是否在雄辩中被软删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆