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

Alphy Gacheru's avatar

How to add a button in a stat to show a modal with a form to update stock

Below is my widget for displaying the remaining stock of different categories. I want to add a + icon or button for every stat that displays a modal when clicked that I can use to add stock count.

<?php

namespace App\Filament\Widgets;

use App\Models\Category;
use App\Models\Customer;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Str;

class StockTypeOverview extends BaseWidget
{
    protected static ?int $sort = 0;

    protected static ?string $pollingInterval = null;

    protected function getStats(): array
    {

        $categories = Category::all();
        $stats = [];

        foreach ($categories as $category) {
            if ($category) {
                $soldQuantity = $category->sales()->sum('quantity');
                $stats[] = Stat::make('Remaining ' . Str::plural($category->name), $category->stock - $soldQuantity);
            }
        }

        return $stats;
    }
}
0 likes
0 replies

Please or to participate in this conversation.