syrian-open-source/laravel-relational-metrics
A Laravel package for calculating relational metrics from Eloquent models, letting you define and query counts, sums, averages, and other aggregates for dashboards, reports, and insights with clean, reusable code.
What it is (as scoped): a thin convenience layer over Eloquent's query builder that produces metric values (counts, aggregates) scoped to a model, to a model's relations, or to a set of conditions. The value proposition is developer ergonomics: turn multi-condition aggregate queries into a fluent, reusable call instead of hand-written selectRaw / withCount chains.
Architecture fit: Reasonable. It appears to be a standard Laravel package — service provider, config publish, likely a trait or facade consumed from model or controller/service code. That means it sits on the read path and doesn't require a schema change, a queue, a new datastore, or a sidecar. It composes with the existing ORM rather than replacing it, so it's low-coupling by construction. It is not an analytics or reporting platform; treat it as sugar over SQL aggregates, appropriate for admin dashboards, KPI cards, gating rules, and per-tenant counters — not for high-cardinality, ad-hoc, or historical reporting.
Integration feasibility: High in isolation — one Composer dependency, one config file, one trait. The real feasibility question is version fit, not effort.
Technical risk (material):
withCount, withSum/withAvg/withMax, whereRelation, and whereHas natively. A large share of this package's stated surface may be reproducible in ~30 lines of in-house query-object code we own outright. That reframes the decision from "integrate a dependency" to "avoid a dependency."Key questions to answer before commitment:
composer require blocked by constraints?Stack fit: Native Laravel/PHP, Composer-installed, no runtime (no Node, no queue worker, no new service). Fits our stack profile with essentially zero platform work — the friction is entirely version compatibility and ownership.
Migration path: None required. This is additive: adopt on one surface, and removal is a composer remove plus rewriting call sites, provided we isolate it behind our own boundary.
Compatibility: Pin an exact version, do not use a floating constraint. Run the install as a spike against our actual Laravel version and PHP version before any design work. If constraints conflict, decide immediately between (a) fork-and-patch, (b) vendor the handful of useful methods, or (c) abandon and use native Eloquent — do not burn time on constraint gymnastics for a 26-star package.
Sequencing:
toSql/query log) and review for full scans and scope leakage.MetricsRepository / query-object layer) so no controller, Blade template, or Livewire component calls the package directly. This is the single most important step: it converts an abandoned package from an outage risk into a reimplementation task.selectRaw baseline.Compatibility guardrail: add the package to a dependency-watch list and run composer audit in CI; a stale package with no security policy is a quiet liability.
Maintenance: Effectively zero upstream maintenance. We inherit the code. Budget an owner (one backend engineer, part-time) with a standing expectation of a fork — patching a Laravel-version incompatibility or a scope bug ourselves is a plausible, not hypothetical, event. That's cheap for 500 lines of query sugar; it would be disqualifying for an auth or payments library.
Support: No vendor, no SLA, no security contact. Support model is "read the source." Acceptable for an internal read-path convenience; unacceptable anywhere it gates money movement, billing, entitlements, or compliance reporting unless we own the fork and the tests.
Scaling: The performance ceiling is the underlying SQL, not the package. Watch for:
CASE WHEN expressions or multiple subqueries per page load;Failure modes (ranked by likelihood × damage):
Ramp-up: Low. A mid-level Laravel developer is productive in a few hours — the API is idiomatic Eloquent. The real ramp-up cost is not learning the package but debugging it: teaching the team to dump generated SQL and reconcile totals. Include that in the pilot's documentation, not a slide deck.
TPM recommendation: Adopt conditionally and narrowly — pilot on one non-critical, read-only dashboard, behind an internal wrapper, pinned and watchlisted, with a documented native-Eloquent fallback. Given Laravel's native aggregate support and the package's staleness, treat "we reimplemented the 40 lines we actually needed" as a fully acceptable outcome, and be prepared to make that call at the spike gate rather than after the dependency has spread.
How can I help you explore Laravel packages today?