Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Stats

Laravel Stats Laravel Package

spatie/laravel-stats

Lightweight Laravel package to track and summarize database stat changes over time. Create a stats class, call increase/decrease on events, then query totals and deltas over ranges grouped by day/week/month for easy reporting.

View on GitHub
Deep Wiki
Context7

Track application stat changes over time

Frequently asked questions about Laravel Stats
How do I set up spatie/laravel-stats for tracking user signups in Laravel?
First, create a stats class extending `BaseStats` (e.g., `SignupStats`). Then call `SignupStats::increase()` in your signup controller or event listener. Run `php artisan migrate` to set up the database tables. Query results later using the fluent `StatsQuery` API with time ranges like `groupByDay()` or `groupByWeek()`.
Does this package work with Laravel 11 or 12? What’s the latest supported version?
Yes, `spatie/laravel-stats` supports Laravel 10 through 13, including Laravel 11 and 12. The package is actively maintained, with the latest release in April 2026. Check the [GitHub repo](https://github.com/spatie/laravel-stats) for version-specific notes.
Can I track custom metrics like API call counts or payment failures with this package?
Absolutely. Create a dedicated stats class (e.g., `ApiCallStats` or `PaymentFailureStats`) and use `increase()`/`decrease()` to log events. The package supports any metric type, including custom attributes or relationships, as long as you extend `BaseStats`.
How do I query stats for a specific time range, like the last 30 days grouped by day?
Use the fluent `StatsQuery` API: `YourStats::query()->start(now()->subDays(30))->end(now())->groupByDay()->get()`. This returns an array of objects with `value`, `increments`, `decrements`, and `difference` for each day. You can chain methods like `groupByWeek()` or `groupByMonth()` for other granularities.
Will this package slow down my Laravel app if I track thousands of metrics?
The package is lightweight and optimized for performance, but heavy queries (e.g., large time ranges) may impact speed. For production, cache frequent queries with Redis or implement Laravel Scheduler jobs to batch updates. The package also supports bulk inserts to reduce database load.
How do I clean up old stats data to avoid bloating my database?
There’s no built-in retention policy, so you’ll need to manually delete old stats. Use Laravel Scheduler to run a cleanup job (e.g., `StatsCleanup::deleteOlderThan(Carbon::now()->subYears(1))`). Alternatively, add a `deleted_at` column and use soft deletes with Eloquent.
Can I integrate this with Laravel Nova or Filament for a dashboard?
Yes, but you’ll need to build a custom resource or widget. The package provides structured data (e.g., `value`, `increments`) that you can display in Nova/Filament tables, charts, or cards. Example: Use Nova’s `DetailResource` to show stats over time or Filament’s `LineChart` for visualizations.
Does spatie/laravel-stats support real-time analytics like live counters?
No, this package is designed for batch updates (e.g., `increase()`/`decrease()` calls) and aggregated queries, not real-time streaming. For live counters, consider pairing it with Laravel Echo or a dedicated real-time analytics tool like Laravel Analytics or Prometheus.
How do I test my stats logic in PHPUnit? Can I mock the database?
Use Laravel’s testing helpers to mock the `BaseStats` class or its database interactions. For example, in a test: `$this->partialMock(YourStats::class, ['increase'])->expects($this->once())->method('increase');`. The package’s stateless design makes it easy to test without a full database setup.
Are there alternatives to spatie/laravel-stats for Laravel analytics?
Yes. For lightweight self-hosted analytics, consider `laravel-analytics` or custom PostgreSQL timeseries tables. For real-time metrics, try Prometheus or Grafana. If you need external integrations (e.g., Mixpanel), use their SDKs alongside this package for hybrid tracking.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai