Challenges faced implementing laravel code snippets project

1. Showing appropriate post count for community and topic

$communities = Community::with(['topics'])->where('user_id', auth()->id())->orderBy('id', 'desc')->get();
@forelse ($community->topics as $topic)
	{{ $topic->name  }} ({{ $topic->posts->where('community_id',$community->id)->count() }})
@empty
	
No topics yet.</small> @endforelse

2. Deleting comments from Communities, Topics controller ( if community/topic is deleted all posts and comments will be deleted )

Comment::where('post_id',$community->posts->pluck('id'))->delete();
$community->posts->each->delete();
$community->topics->each->delete();
$community->delete();

sdf

Related Posts