- How do I add a simple count stat for users in the last 30 days to my Filament dashboard?
- Use `SimpleStat::make(User::class)->last30Days()->dailyCount()` in your widget’s `getStats()` method. This generates a prebuilt stat card with a trend chart for daily user counts over the last 30 days. No additional setup is needed beyond requiring the package.
- Does this package work with Laravel 11 or older versions?
- The package officially supports Laravel 12/13. For Laravel 11 or older, you’ll need to manually adjust dependencies (e.g., downgrade `filament/widgets` to v4) or use a forked version. Check the GitHub issues for community patches.
- Can I customize the time range for stats beyond 'last30Days'?
- Yes, you can chain methods like `last7Days()`, `lastYear()`, or `between($startDate, $endDate)` to any stat. For custom ranges, use `between()` with Carbon instances or `customRange()` for full flexibility.
- How do I filter stats by a specific condition, like completed orders?
- Use Eloquent query methods like `where()` directly on the stat. For example: `SimpleStat::make(Order::class)->where('status', 'completed')->last7Days()->dailySum('amount')`. This filters the underlying query before aggregation.
- Will these stats impact my dashboard performance if I have millions of records?
- For large datasets, enable Laravel’s query caching (e.g., `Cache::remember()`) or optimize your database with indexes on filtered columns. The package itself doesn’t cache, but you can wrap `getStats()` in a cached closure or use materialized views for critical metrics.
- Can I use this package with non-Filament dashboards or other admin panels?
- No, this package is designed specifically for Filament widgets. For other admin panels, you’d need to rebuild the stat logic manually or create a wrapper. The core trend functionality (via `laravel-trend`) could be reused, though.
- How do I disable the trend chart for a specific stat?
- Call `withoutTrend()` on the stat builder. For example: `SimpleStat::make(Model::class)->last30Days()->dailyCount()->withoutTrend()`. This will show only the raw value without the comparison chart.
- Are there alternatives if I need more complex aggregations like averages or custom SQL?
- For advanced aggregations, consider `laravel-trend` directly or packages like `spatie/laravel-analytics`. This package focuses on counts/sums with trends, but you can extend it by overriding the query builder or using raw SQL via `selectRaw()`.
- How do I test my Filament widgets with these stats in a CI pipeline?
- Mock the `getStats()` method in your widget tests using Laravel’s testing helpers. For example: `Widget::fake()->withStats([...])`. Ensure your test database has sample records to avoid null queries. The package itself is well-tested via GitHub Actions.
- Can I invert the trend colors for metrics where decreases are positive (e.g., error rates)?
- Yes, use `invertTrendColors()` on the stat builder. For example: `SimpleStat::make(ErrorLog::class)->last30Days()->dailyCount()->invertTrendColors()`. This flips the color logic to highlight reductions as improvements.