henryoladj
1 week ago
157
11
Laravel

How to get total number of posts made by all users

Posted 1 week ago by henryoladj

Controller.php

public function index(Request $request)
    {
       
        if($request->has('tags')){
            $tag=Tag::find($request->tags);
            $news=$tag->news;
        }else{
        $news = News::with(['post as post_count' => function($query) {
        return $query->latest()->limit(5)->paginate(15);
        }])->get(); 
        }
        return view('pages.welcome',compact('news', 'tags'));
    }

Then i tried displaying it with this

{{$news->post_count}}

It is not showing any number

Please sign in or create an account to participate in this conversation.