F
Filament9mo ago
Mina

Is there a way to group stat widgets on admin panel?

Hi, I have 4 different widgets that I'm fetching in my AdminPanelProvider. The thing is, i hate the way they look. Is there a way to make them all in one row? Here's the code:
->widgets([ ShopOverview::class, FunnelOverview::class, FunnelOverview::make([ 'label' => 'Total Draft Funnels', 'status' => \App\Models\v1\Funnel::STATUSES[FunnelStatus::DRAFT], ]), FunnelOverview::make([ 'label' => 'Total Active Funnels', 'status' => \App\Models\v1\Funnel::STATUSES[FunnelStatus::ACTIVE], ]), FunnelOverview::make([ 'label' => 'Total Paused Funnels', 'status' => \App\Models\v1\Funnel::STATUSES[FunnelStatus::PAUSED], ]), ChargeOverview::make([ 'label' => 'Total Recurring Charges', 'type' => 'RECURRING', ]), ChargeOverview::make([ 'label' => 'Total Usage Charges', 'type' => 'USAGE', ]),
No description
9 Replies
Mina
MinaOP9mo ago
If you want me to provide more code, I'll be happy to oblige does anyone have an idea? I am at a complete loss
Mina
MinaOP9mo ago
I don't want to make the custom dashboard
sandofgods
sandofgods9mo ago
you have to, to have more than two widget, but it's really simple to do it and your not loosing nothing.
Mina
MinaOP9mo ago
first, that's a version 2, I am using version 3, so there's nothing of that sort in the documentation. Second, it's really not about is it simple or not to make a custom dashboard, my project doesn't require a custom one. So, I reverted everything back to how I originally had and I hated the solution I've came up before since I had to use selectRaw for queries to load the different data. It's an ugly code. The second solution was to actually separate all the data in separate widgets so that I can actually utilize Filaments built in functions for query building. But it looks ugly.
Disouric
Disouric9mo ago
Just put it all in the same widget? Get the data externally using classes so you'll still get clean code
Mina
MinaOP9mo ago
it is all in the same widget now this is the code from before, I was told to redo the widgets: protected function getStats(): array { $totalShops = User::query()->isActive()->count(); $funnelStats = Funnel::live() ->selectRaw('status, COUNT(*) as totalFunnels') ->groupBy('status') ->pluck('totalFunnels', 'status') ->all(); $totalFunnels = array_sum($funnelStats); $totatlDraftFunnels = $funnelStats[1] ?? 0; $totalActiveFunnels = $funnelStats[2] ?? 0; $totalPausedFunnels = $funnelStats[3] ?? 0; $chargeStats = Charge::where('status', '!=', 'CANCELLED')->selectRaw(" SUM(CASE WHEN type = 'RECURRING' THEN 1 ELSE 0 END) as totalRecurringCharges, SUM(CASE WHEN type = 'RECURRING' THEN price ELSE 0 END) as recurringChargesSum, SUM(CASE WHEN type = 'USAGE' THEN 1 ELSE 0 END) as totalUsageCharge, SUM(CASE WHEN type = 'USAGE' THEN price ELSE 0 END) as totalUsageChargeSum ")->first(); $totalRecurringCharges = $chargeStats->totalRecurringCharges ?? 0; $recurringChargesSum = '$'.($chargeStats->recurringChargesSum ?? 0); $totalUsageCharge = $chargeStats->totalUsageCharge ?? 0; $totalUsageChargeSum = '$'.($chargeStats->totalUsageChargeSum ?? 0); return [ Stat::make('Total Active Shops', $totalShops), Stat::make('Total Funnels', $totalFunnels), Stat::make('Total Draft Funnels', $totatlDraftFunnels), Stat::make('Total Active Funnels', $totalActiveFunnels), Stat::make('Total Paused Funnels', $totalPausedFunnels), Stat::make('Total Recurring Charges', $totalRecurringCharges), Stat::make('Recurring Charges Sum', $recurringChargesSum), Stat::make('Total Usage Charges', $totalUsageCharge), Stat::make('Usage Charges Sum', $totalUsageChargeSum), ]; } it's an ugly code but I've gotten no instructions on how to fix it
Disouric
Disouric9mo ago
You could move all the variables to different functions
Want results from more Discord servers?
Add your server