本文介绍了withCount()不包括已删除的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使withCount('comments')也包括所有已删除/已整理的行?
How can I make withCount('comments') also include all deleted/trashed rows?
例如,如果我有5条注释,而我删除了1条,我仍然希望withCount('comments')返回5条,但返回4条.
For example, if I have 5 comments, and I delete 1, I still expect withCount('comments') to return 5, but instead it's returning 4.
我的完整查询看起来像这样:
My full query looks something like this:
$query = Post::withTrashed() ->withCount('comments') ->get();推荐答案
我认为您可以尝试
$query = Post::withCount('comments') ->withTrashed() ->get();OR
$query = DB::table('post') ->select('comments', DB::raw('count(*) as comments')) ->get();希望这项工作对您有用!
Hope this work for you!
更多推荐
withCount()不包括已删除的行?
发布评论