我怎样才能使withCount('comments')
还包括所有已删除/废弃的行?
例如,如果我有 5 条评论,我删除了 1 条,我仍然期望withCount('comments')
返回 5,但实际上返回了 4。
我的完整查询如下所示:
$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();
希望这对你有用!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)