我正在 Laravel 5.5 中构建 Eloquent 查询。我只想知道数据库中是否存在一行 - 我想包括任何软删除的行:
$query = Thing::where([
'date' => $date,
'user_id' => $userId
]);
return $query->exists();
我的问题是这会忽略软删除的行,因此它将返回 false
如果具有给定 date
的软删除行和 user_id
存在。有没有一种巧妙的方法来包含软删除的行?
最佳答案
是的,使用 Thing::withTrashed()->where(...)
。
文档:https://laravel.com/docs/5.5/eloquent#querying-soft-deleted-models
关于mysql - Laravel exists() 忽略软删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48165351/