Stats

The starter includes a simple stats system that pre-calculates counts and stores them in a stats table. An admin endpoint serves the data, and a scheduled command keeps it fresh.

How It Works

A single StatsService defines the queries and date ranges. The stats:calculate command runs it on a schedule. Each stat is stored as a row keyed by group and a compound key (metric + range).

Stats are calculated across four date ranges:

  • all - total count, no date filter
  • today - created today (in configured timezone)
  • yesterday - created yesterday
  • day_before - created two days ago

The timezone defaults to America/New_York and is configurable via config/stats.php.

Groups

Stats are organized into groups. The command accepts a --group option to calculate only a specific group.

  • subscriptions - signups per plan, active subscriptions per plan and interval
  • bookmarks - total bookmarks
  • categories - total categories
  • tags - total tags

Subscription stats are dynamic. They auto-expand based on however many plans exist and which pricing intervals each plan has configured.

Admin Endpoint

GET /admin/stats returns all stats. Pass ?group=subscriptions to filter to a single group.

Adding New Stats

Add queries to the queries() method in StatsService. Return an Eloquent builder keyed by group and metric name. The service handles date filtering and persistence automatically.

© Websanova 2026 About Privacy