- What is finller/laravel-kpi used for?
- It is a Laravel package for defining, calculating and caching key performance indicators and storing their values over time. You build fluent KPI classes, let the package compute and cache the results, then retrieve historical values through a clean API. It is aimed at dashboards, reporting screens and monitoring where you need trends and period-over-period comparisons without writing the boilerplate yourself.
- How do I install finller/laravel-kpi?
- Install it with Composer using composer require finller/laravel-kpi. Laravel's package auto-discovery registers the service provider, so no manual provider entry is normally needed. Check the repository readme for any publish or migration steps that apply to your version before using it in an existing app.
- Where are KPI values stored and do I need to run migrations?
- The package keeps KPI measurements over time so you can analyse and retrieve them later, which means it needs persistent storage in your database. That typically involves publishing and running the package migrations as described in the readme. If your app already has a metrics table you may need to adapt or review the default setup rather than relying on it as-is.
- How do I define a custom KPI in Laravel?
- You create a KPI class that describes the metric and how its value is calculated, keeping the logic in one testable place instead of scattering queries across controllers. The fluent API lets you chain configuration for things like the value resolver, caching and time handling. Once defined, you reference that class wherever you need the current or historical value.
- Does laravel-kpi cache results and how do I refresh them?
- Yes, caching is a core part of the package: calculated KPI values are cached so repeated dashboard requests do not re-run expensive queries on every page load. You control caching as part of the KPI definition, and you should clear or recalculate a KPI when the underlying data changes materially. For frequently changing metrics, prefer a scheduled recalculation over cache-busting on every request.
- Which Laravel and PHP versions does finller/laravel-kpi support?
- The exact constraints are declared in the package's composer.json, so check that file or the readme before adding it to an older application. Because the package is actively maintained, the supported Laravel and PHP ranges track relatively recent releases. If you are on an end-of-life Laravel version, pin a compatible package release or plan an upgrade first.
- Can I compare a KPI between two time periods?
- Yes, period comparison is one of the package's main features: you can retrieve a KPI for a given period and compare it with a previous one, which is what most dashboard trend indicators need. This saves you from writing your own date-range grouping and delta calculations. Use Carbon's test-now helper in tests so period boundaries stay deterministic.
- How do I test KPI calculations in my Laravel app?
- KPI classes are ordinary PHP classes, so you can instantiate them in a feature or unit test and assert the calculated value against known fixture data. Freeze time with Carbon::setTestNow so date-based periods and comparisons are reproducible, and seed deterministic records rather than relying on production-like data. Also test the cached path separately if your KPI exposes caching behaviour.
- Is laravel-kpi suitable for production dashboards with large datasets?
- It can be, provided you lean on caching and avoid recalculating heavy aggregations on every request. For large tables, make sure the queries behind your KPI classes are indexed on the columns used for filtering and date ranges. A common pattern is to recalculate KPIs on a schedule or queue and let the dashboard read the cached values.
- What are the alternatives to finller/laravel-kpi?
- You can hand-roll KPI queries with the query builder and cache them yourself, use a broader analytics or metrics service, or adopt a dedicated time-series store for very high-volume data. The advantage of this package is that it keeps KPI definitions, caching and period comparison in fluent classes inside your Laravel codebase, with far less boilerplate. If you only need one or two simple counts, custom queries may be enough.