- How do I install bilfeldt/laravel-route-statistics in a Laravel app?
- Install it with composer require bilfeldt/laravel-route-statistics, then publish and run the migrations and publish the config file. Enable logging with the global middleware in bootstrap/app.php, the routestatistics route middleware alias on selected groups, or the $request->routeStatistics() macro for conditional or controller-level logging. Starting with a scoped route group lets you measure write cost and row growth before widening.
- Which Laravel and PHP versions does laravel-route-statistics support?
- Version 4 supports Laravel 10, 11, 12, and 13 on PHP 8.2 through 8.5. Older major versions map to older Laravel and PHP combinations, so check the package's version matrix before upgrading. This matters because the package depends on a sibling request-logger package, so two version constraints move together.
- How does route statistics aggregation work and why does it reduce database size?
- The middleware tags a request, the sibling request-logger package persists it, and this package supplies the migration, config, model, commands, and aggregation semantics. Aggregation happens at write time by bucketing the date column to second, hour, day, or month and incrementing a counter. That collapses many requests into one row instead of storing every request, which keeps database usage minimal.
- Does laravel-route-statistics support queued logging for production?
- Yes, queued logging was added in version 2.1.0 and is the lever that makes the package acceptable on a hot path. Without it, synchronous logging adds a database round-trip to every instrumented request, so a saturated database can degrade user-facing latency. If you queue it, run workers and account for slightly delayed statistics.
- What data does laravel-route-statistics store and is it a privacy concern?
- The package stores user_id, IP address, and route parameters by default, which is personal data in many jurisdictions. Treat that as an explicit configuration and governance decision rather than a default, and decide whether route parameters might contain tokens, emails, or free text. Pair that decision with a retention window and access controls.
- Does the package include retention or pruning for old route statistics?
- No, the package does not ship a retention scheduler or prune job; it explicitly leaves purging to you. You need to own a scheduled prune job and a retention window, especially if you enable logging broadly. Purging old rows is part of keeping the single statistics table and its indexes healthy.
- Can I use laravel-route-statistics with multi-tenant apps or a custom user model?
- It has a first-class team_id column and a configurable user relation, added in v3.4.0, so conventional multi-tenant apps with a single users model map onto it directly. If your tenancy key is an organization, workspace, or tenant UUID instead of team_id, you need custom context injection. It is not a general-purpose analytics platform for arbitrary dimensions.
- How do I test laravel-route-statistics in a Laravel feature test?
- Use Laravel feature tests around a route with the middleware enabled, then assert rows in the package's statistics table. If queued logging is enabled, fake or run the queue so the assertions are deterministic. Also test that exceptions and aborted requests behave the way your instrumentation scope expects.
- What are the alternatives to laravel-route-statistics, such as Laravel Pulse or Telescope?
- Laravel Pulse and Telescope overlap with this package if you already run them, but they answer different questions: this package counts route usage and aggregates it, while Pulse and Telescope are broader observability tools. The package has no read API or dashboard, so anything beyond php artisan route:stats and route:unused is your own SQL. Choose it when you want lightweight route-level usage counts, not request forensics or sub-route behavioural analytics.
- Is bilfeldt/laravel-route-statistics actively maintained and safe for production use?
- Adoption signal is modest: around 240 stars, zero Packagist dependents, and effectively one maintainer plus bot-driven compatibility PRs. Recent releases for Laravel 13 and PHP 8.5 show responsiveness, and MIT licensing plus a small surface area make forking cheap. Price in the sibling-package version coupling, hot-path writes, and data governance before enabling it broadly.