- How do I install spatie/filament-simple-stats in a Laravel app?
- Install it with composer require spatie/filament-simple-stats. There are no migrations, no publishable config, and no assets to publish, so installation is a single Composer command. You then use SimpleStat inside the getStats() method of an existing Filament widget class. The package requires a Filament 5.2+ admin panel to be useful.
- Which Filament and Laravel versions does this package support?
- Version 1.1.0 and later require Filament widgets ^5.2, and version 1.2.0 and later add Laravel 13 support. If you are still on Filament 4 you must pin to 1.0.0 and treat that branch as unmaintained. Because the package follows Filament majors closely, a Filament upgrade can turn this dependency into a Composer conflict, so pin explicitly and test upgrades.
- How do I add a daily count stat card to a Filament dashboard?
- Return a SimpleStat instance from your widget's getStats() method. For example, SimpleStat::make(User::class)->last30Days()->dailyCount() renders a stat card with a daily count trend over the last 30 days. The fluent chain is only a few calls, so time to a visible dashboard figure is typically measured in hours.
- Can I sum a column instead of counting rows?
- Yes. Chain dailySum() with a column name, for example SimpleStat::make(Purchase::class)->last30Days()->dailySum('earnings'). This aggregates the column per day across the selected period, which is useful for revenue, credits, or usage totals. The result is displayed through the standard Filament Stat widget rendering.
- Can I filter the stat query with a where clause or an Eloquent builder?
- You can call where() on the SimpleStat to constrain the underlying query. Since 1.2.1 you can also pass an Eloquent Builder, which means existing scoped queries for tenant, permission, or ownership filters can be reused instead of reimplemented. That builder support is the most important change for teams standardizing widgets across an application.
- Does the package handle multi-tenancy automatically?
- No. Scoping is not enforced centrally; each widget is responsible for the query it emits. In a multi-tenant application you should pass a pre-scoped Eloquent Builder or add the tenant where() condition on every widget. Decide as a team whether scoping lives in a shared base widget or in per-widget code before rolling this out widely.
- Is it safe to use on large tables, and does it cache results?
- There is no caching layer, so every stat issues at least two range aggregates: the current period and the comparison period. A dashboard with eight widgets therefore runs sixteen COUNT or SUM scans over a date range on each render. On large orders or events tables, add composite indexes covering the date column and your filters, and consider caching the aggregates yourself if you have a dashboard load budget.
- How accurate is the trend percentage, and how are timezones handled?
- The widget reports percentage change between the current and comparison periods, so a zero baseline, timezone drift at day boundaries, and inverted metrics such as costs or error rates can all produce a number that is technically correct but operationally misleading. Check the aggregate output against a known-good query before quoting dashboard figures. If you are migrating from hand-rolled widgets, run both side by side for a release cycle and compare.
- How do I test Filament widgets built with this package?
- Test them like any other Filament or Livewire widget by rendering the dashboard page or widget and asserting the stat output. Because the package only delegates to Eloquent aggregates, seeding a small dataset with known counts per day lets you assert exact values and percentages. Keep timezone-sensitive tests fixed to a single application timezone to avoid flaky day-boundary assertions.
- What are the alternatives to spatie/filament-simple-stats?
- The closest substitute is using flowframe/laravel-trend directly inside a custom Filament Stat widget, which gives you upstream fixes and full control over rendering. Filament's own chart widgets are a better fit if you need explorable or drill-down analytics rather than stat cards. For Nova, Backpack, or hand-rolled Blade admins this package has no role at all, so a custom implementation is the only option.