我有评论部分,但我只想检索已删除的评论(仅当父级实际上已删除时)
Invite::forWedding($wedding)->withTrashed()->with([
"comments" => function ($query) {
// I want to check that "Invite" is trashed , else return unfiltered;
return $query->withTrashed();
}
, "comments.user"
]
)->findOrFail($id);
答案 0 :(得分:0)
我认为您可以直接查询父表中的deleted_at
列。
也许是这样的:
Invite::forWedding($wedding)->withTrashed()->with([
"comments" => function ($query) {
$query->whereNotNull('comments.deleted_at');
$query->whereNotNull('invites.deleted_at');
}
, "comments.user"
]
)->findOrFail($id);