Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Neeraj1005's avatar

Creating Report section in Admin panel in Laravel:

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?

0 likes
5 replies
Tray2's avatar
Tray2
Best Answer
Level 73

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.

Neeraj1005's avatar

@tray2 In my view file, I have created a separate box for Users and Post. so how to call this?

Tray2's avatar

You pass it from your controller

return view('your.view')->with(['user_count' => $userCount, 'published_post_count' => $publishedPostsCount]);

And in you view

{{ $user_count }}

{{ $published_post_count }}
1 like
Neeraj1005's avatar

@tray2 thank you it's working.. similarly, I want to display these in a chart (chart.js) form. So how can achieve this?

Tray2's avatar

I've never used chart.js but you most likely pass the numbers as parameters to some js function.

In your view it could look something like

<script>
    renderChart({{ $user_count }});
</script>
1 like

Please or to participate in this conversation.