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 Metrics

Laravel Metrics Laravel Package

eliseekn/laravel-metrics

View on GitHub
Deep Wiki
Context7

Generate easily metrics and trends data of your models for your dashboards.

Frequently asked questions about Laravel Metrics
How do I install Laravel Metrics for Laravel 11/12?
Run `composer require eliseekn/laravel-metrics` in your project directory. The package requires PHP 8.2+ and Laravel 11/12. For Laravel 13, check the 4.x branch in the GitHub repo.
Can I use this package with non-Eloquent queries (e.g., raw DB tables)?
Yes. Use `DB::table('your_table')` or any Query Builder instance with `LaravelMetrics::query()`. It supports custom tables, joins, and even non-model data.
Does Laravel Metrics support PostgreSQL or SQLite?
Yes, the package is tested and supported on MySQL, PostgreSQL, and SQLite. The changelog notes fixes for PostgreSQL/SQLite edge cases, but ensure your queries are indexed for performance.
How do I generate monthly trends for a model like `Order`?
Use the fluent chain: `LaravelMetrics::query(Order::query())->sum('amount')->byMonth(6)->trends()`. This returns an array of monthly sums for the last 6 months. Replace `sum()` with `count()` or other aggregations.
Can I customize the date column (e.g., use `published_at` instead of `created_at`)?
Yes. Add `.dateColumn('published_at')` to your chain. This overrides the default `created_at` column for time-based grouping (e.g., `byMonth()`, `byDay()`).
Will this work for real-time dashboards (e.g., live updates)?
No. Laravel Metrics is optimized for batch/periodic metrics (e.g., daily/monthly trends). For real-time data, consider caching results (e.g., Redis) or a dedicated service like Laravel Echo with WebSockets.
How do I group metrics by a custom column (e.g., `status` or `category`)?
Use `.labelColumn('status')` or `.labelColumn('category')` in your chain. This groups the output by the specified column, useful for segmented analytics like `count by status`.
Does Laravel Metrics integrate with frontend frameworks like Chart.js or Inertia?
No. The package returns raw arrays/collections (e.g., `[['month' => 'Jan', 'value' => 100]]`). You’ll need to process this data in your frontend (e.g., Chart.js) or Laravel views.
What if my database queries are slow for large datasets?
Add indexes to date/aggregation columns (e.g., `created_at`, `amount`). For frequent requests, cache results in Redis or implement a scheduled job to precompute metrics. Avoid large date ranges (e.g., `between('2010-01-01', now())`) without optimization.
Are there alternatives for Laravel metrics with caching or real-time support?
For caching, pair this with Laravel’s cache or Redis. For real-time, consider `spatie/laravel-analytics` (event-based) or `laravel-echo` with a queue. If you need a single package, `beberlei/doctrineextensions` (for Doctrine) or `laravel-trends` (legacy) are alternatives, but Laravel Metrics offers deeper Eloquent integration.
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.
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
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata