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 Easy Metrics

Laravel Easy Metrics Laravel Package

sakanjo/laravel-easy-metrics

Laravel package to quickly build app metrics (value, trend, bar, line, pie, doughnut, polar). Supports ranges, aggregates (count/sum/min/max/avg), and growth rates. Designed to work with Laravel and Filament widgets for dashboards.

View on GitHub
Deep Wiki
Context7

Generate metrics with ease and precision.

Frequently asked questions about Laravel Easy Metrics
How do I integrate this package with Filament widgets for dashboards?
The package includes built-in support for Filament widgets. Use the fluent API to generate metrics like `Trend::make(User::class)->countByMonths()` and pass the results directly to Filament’s chart widgets. The README provides a practical example for Filament v3 widgets, showing how to replace raw queries with EasyMetrics calls for cleaner, reusable code.
Does this package support custom date ranges or time periods?
Yes, the package supports custom ranges via methods like `countByDays()`, `countByMonths()`, and `countByYears()`. You can also define custom ranges using the `range()` method or leverage predefined ranges such as weekly, monthly, or yearly intervals. This makes it easy to visualize trends over specific periods.
What Laravel and PHP versions are officially supported?
The package is officially tested and supported for Laravel 10.x and PHP 8.0+. While it may work with Laravel 9.x or 11.x, there are no guarantees, and adjustments might be needed. Always check the package’s release notes or GitHub issues for updates on compatibility.
Can I use this package with non-Eloquent data sources like API responses or external databases?
No, this package is designed specifically for Eloquent models and Laravel’s query builder. It relies on Eloquent’s fluent interface for generating metrics, so it won’t work directly with non-database data sources like API responses or NoSQL databases. For those use cases, you’d need to pre-process the data into an Eloquent-compatible format.
How do I handle growth rates for metrics like revenue or user counts?
The package includes dedicated methods for calculating growth rates, such as `growthRate()` and `growthRateType()`. You can apply growth rates to Value, Trend, or Doughnut metrics. For example, `Value::make(Order::class)->sum('amount')->growthRate()` will calculate the percentage growth compared to a previous period. Supported growth rate types include percentage, absolute, and custom formulas.
Are there performance considerations for large datasets (e.g., 100K+ records)?
Yes, the package can introduce performance bottlenecks for large datasets, especially with time-series aggregations like `countByMonths()` or `countByDays()`. These queries often involve expensive GROUP BY operations. To mitigate this, ensure your database tables have proper indexes on date/time columns and consider caching results using Laravel’s cache or Redis. Always benchmark with your target dataset size.
Does the package include caching for metrics to reduce database load?
No, the package does not include built-in caching. You’ll need to implement caching manually using Laravel’s cache or Redis. For example, you can cache the results of `Trend::make(User::class)->countByMonths()` for a specific duration to reduce database queries. The package’s fluent design makes it easy to wrap metric calls in caching logic.
How do I customize labels or data transformations for metrics like pie or doughnut charts?
You can customize labels using the `getLabel()` method or override it in your own metric classes. For example, if you’re using an enum for categories, you can transform raw values into human-readable labels. The package also supports custom ranges and aggregations, allowing you to tailor metrics to your domain-specific needs.
Are there any known issues with PostgreSQL compatibility, like date truncation functions?
The package claims compatibility with both MySQL and PostgreSQL, but there may be subtle differences in how date functions like `DATE_TRUNC` or `DATE_PART` are handled. If you encounter issues, check the package’s GitHub issues or test your queries directly in PostgreSQL to ensure they return the expected results. Always verify with your target database.
What alternatives exist for generating metrics in Laravel if this package doesn’t fit my needs?
If this package’s Eloquent-centric approach doesn’t fit, consider alternatives like Laravel Scout for search-based metrics, custom query builder logic, or packages like Spatie’s Laravel Analytics for more advanced reporting. For non-database metrics, you might use Laravel’s collections or external libraries like Chart.js for client-side visualization. Always evaluate whether your use case requires database-backed metrics or can be handled with other tools.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony