From 2da3264dd1a09c74241cf4312514c9d5243b0d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna-Sara=20S=C3=A9lea?= Date: Fri, 31 Oct 2025 21:48:31 +0100 Subject: [PATCH] Fixed widgets on admin view --- app/Filament/Widgets/AdminWidget.php | 12 +++++------- app/Filament/Widgets/PopularCategoryChart.php | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Filament/Widgets/AdminWidget.php b/app/Filament/Widgets/AdminWidget.php index 1cb4790..138e84b 100644 --- a/app/Filament/Widgets/AdminWidget.php +++ b/app/Filament/Widgets/AdminWidget.php @@ -22,17 +22,15 @@ class AdminWidget extends BaseWidget })->get()->groupBy('item_id'); $itemName = ""; + $itemCount = 0; foreach ($items as $item){ - $itemCount = 0; - - if($item->count() > $itemCount) { + if(count($item) > $itemCount) { $itemName = $item[0]->item->desc; - $itemCount = $item->count(); - } - - + $itemCount = count($item); + } } + return [ //Card::make(__('Total number of users'), User::count() ), Stat::make(__('Total amount of games'), Item::where('type', 'game')->count() ), diff --git a/app/Filament/Widgets/PopularCategoryChart.php b/app/Filament/Widgets/PopularCategoryChart.php index be5306a..5e63ef2 100644 --- a/app/Filament/Widgets/PopularCategoryChart.php +++ b/app/Filament/Widgets/PopularCategoryChart.php @@ -25,7 +25,9 @@ class PopularCategoryChart extends ChartWidget protected function getData(): array { - $categories = Category::where('type', 'game')->get()->sortBy('id')->sortDesc(); + $categories = Category::where('type', 'game')->get()->sortBy('id'); + + //dd($categories); $categoryNames = []; foreach ($categories as $obj){ @@ -34,13 +36,13 @@ class PopularCategoryChart extends ChartWidget $items = Reserveditem::withTrashed()->with('item')->whereHas('item', function($query){ return $query->where('type', 'game'); - })->get()->groupBy('item.category_id')->sortBy('item.category_id')->sortDesc(); + })->get()->groupBy('item.category_id')->sortBy('item.category_id'); $itemCategoriesCount = []; foreach ($items as $item){ - $itemCategoriesCount[] = $item->count(); + $itemCategoriesCount[] = count($item); } return [