- How do I install Laravel Easy Metrics for a Laravel 10.x project?
- Run `composer require sakanjo/laravel-easy-metrics` in your project directory. The package supports Laravel 10.x and PHP 8.0+, with no additional configuration required for basic usage. Ensure your project meets these version requirements before installation.
- Can I use this package with Filament v3 widgets?
- Yes, the package is explicitly designed for Filament v3 integration. The README includes ready-to-copy widget examples for metrics like Value, Trend, and Doughnut. Simply extend Filament’s `Widget` class and use the provided metric methods to populate your dashboard.
- What types of metrics does this package support?
- The package supports six metric types: Value (single aggregate), Trend (time-series), Bar, Line, Pie, Doughnut, and Polar charts. Each type uses Eloquent models and method chaining (e.g., `Value::make(User::class)->count()`) for flexibility. Custom date columns can be specified via `dateColumn()`.
- How do I calculate growth rates with this package?
- Growth rates are supported for Value, Trend, and Doughnut metrics. Use methods like `growthRate()` or `growthRateType()` to specify the calculation type (e.g., percentage, absolute). For example, `Value::make(User::class)->count()->growthRate()` compares the current value to a previous time range.
- Does Laravel Easy Metrics work with PostgreSQL or only MySQL?
- The package claims compatibility with both MySQL and PostgreSQL, but edge cases like time truncation or timezone handling may vary. Test thoroughly with your database engine, especially for custom date ranges or aggregations. No explicit optimizations for PostgreSQL are documented in the current version.
- How do I handle large datasets (e.g., 1M+ records) with this package?
- The package abstracts queries using Eloquent, so performance depends on your database indexing and query optimization. For large datasets, ensure your model uses proper indexes on aggregated columns (e.g., `created_at`). Avoid complex custom ranges without testing; consider caching results for frequent queries.
- Can I customize the date ranges for metrics like Trend or Bar?
- Yes, you can define custom date ranges using methods like `range('custom')` or `dateColumn('custom_date')`. The package includes predefined ranges (e.g., daily, weekly, monthly) but allows full flexibility. For example, `Trend::make(User::class)->range('custom')->between('2023-01-01', '2023-12-31')` lets you specify arbitrary periods.
- Are there any breaking changes in minor versions (e.g., 1.x to 2.x)?
- The package follows semantic versioning, but minor versions *may* introduce breaking changes due to its low adoption and sparse documentation. Always check the changelog or GitHub issues for updates. For stability, consider pinning to a specific version (e.g., `^1.0`) until the package matures.
- Does this package include caching for better performance?
- The package does not include built-in caching mechanisms. You’ll need to implement caching (e.g., Laravel’s cache driver or Redis) manually for metrics that are frequently accessed. Wrap metric calls in `Cache::remember()` or use Filament’s built-in caching for widgets.
- What alternatives exist for Laravel metrics if this package lacks features?
- Alternatives include `spatie/laravel-analytics` (for analytics pipelines), `laravel-excel` (for custom chart exports), or `chartjs/chart.js` (for frontend-only charts). For Filament-specific solutions, consider `filament/panels` with custom widgets or third-party packages like `filament-widgets/stats-overview`. Evaluate based on your need for Eloquent integration or chart types.