Apr 12, 2024
0
Level 3
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;
}
}
Please or to participate in this conversation.