From d7c06c38a67fa6441ae963fe4f835ba4de3fa09b Mon Sep 17 00:00:00 2001 From: kusowl Date: Mon, 2 Feb 2026 17:22:01 +0530 Subject: [PATCH] feature(deals by category pie chart): - add a pie chart that shows deals by category - change UI to make it more clear --- app/Http/Controllers/StatsController.php | 11 ++++ .../DealsCountByCategoryCollection.php | 16 +++++ .../DealsCountByCategoryResource.php | 17 +++++ .../admin/active-users-chart.blade.php | 63 ++++++++++++------- .../admin/category-wise-deals-pie.blade.php | 52 +++++++-------- resources/views/components/layout.blade.php | 2 + routes/api/stats/stats.php | 1 + 7 files changed, 115 insertions(+), 47 deletions(-) create mode 100644 app/Http/Resources/DealsCountByCategoryCollection.php create mode 100644 app/Http/Resources/DealsCountByCategoryResource.php diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index ac9625d..f748276 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -4,6 +4,8 @@ use App\Enums\UserTypes; use App\Http\Resources\ActiveUsersStatsCollection; +use App\Http\Resources\DealsCountByCategoryCollection; +use App\Models\DealCategory; use App\Queries\PageVisitStatsQuery; use Illuminate\Http\Request; @@ -22,4 +24,13 @@ public function getActiveUsers(Request $request, PageVisitStatsQuery $baseQuery) 'activeBrokers' => new ActiveUsersStatsCollection($activeBrokers), ]); } + + public function getDealsByCategory() + { + return new DealsCountByCategoryCollection( + DealCategory::select(['id', 'name']) + ->withCount('deals') + ->get() + ); + } } diff --git a/app/Http/Resources/DealsCountByCategoryCollection.php b/app/Http/Resources/DealsCountByCategoryCollection.php new file mode 100644 index 0000000..c612a3f --- /dev/null +++ b/app/Http/Resources/DealsCountByCategoryCollection.php @@ -0,0 +1,16 @@ + $this->collection, + ]; + } +} diff --git a/app/Http/Resources/DealsCountByCategoryResource.php b/app/Http/Resources/DealsCountByCategoryResource.php new file mode 100644 index 0000000..a7ad8d0 --- /dev/null +++ b/app/Http/Resources/DealsCountByCategoryResource.php @@ -0,0 +1,17 @@ + $this->name, + 'dealsCount' => $this->deals_count, + ]; + } +} diff --git a/resources/views/components/dashboard/admin/active-users-chart.blade.php b/resources/views/components/dashboard/admin/active-users-chart.blade.php index d33b817..f6ef83a 100644 --- a/resources/views/components/dashboard/admin/active-users-chart.blade.php +++ b/resources/views/components/dashboard/admin/active-users-chart.blade.php @@ -1,35 +1,56 @@
- - - - - + +
+

User Activity

+ + + + - - - + + + - - - - + + + + +
-
+
@push('scripts') - +