The easiest way is to put something like this in your controller
$userCount = User::count();
$publishedPostsCount = Post::where('published_at', '!=', null)->count():
And then pass them to your view like you usually do.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
In my dashboard section, I want to create a report section. Where I want to show and count how many users have joined and how many posts have been published.
For example:
Am working on a System where the Admin has 3 Tables, Post, Category and Users and What am trying to achieve is this: When the Admin logs in, He sees the Total Count of each Tables Example: Total Posts: 10, Total Users: 5, Total Category: 5.
Please suggest. How can I achieve this What Controller Function do I need to Write and How do I pass it to the View?
The easiest way is to put something like this in your controller
$userCount = User::count();
$publishedPostsCount = Post::where('published_at', '!=', null)->count():
And then pass them to your view like you usually do.
Please or to participate in this conversation.