How to check if row is soft-deleted in Eloquent?

DisgruntledGoat picture DisgruntledGoat · Nov 30, 2015 · Viewed 30.4k times · Source

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) { ... }

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

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

Answer

DisgruntledGoat picture DisgruntledGoat · Nov 30, 2015

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.

So I can write

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