Skip to main content
Back to packages
106 GitHub stars

eliseekn/laravel-metrics

View on GitHub

Description

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

Usage

With Eloquent Query

Import the Eliseekn\LaravelMetrics\LaravelMetrics class in your controller and use it as follows :

  • Basic usage
// generate trends of products amount's sum for the current year
LaravelMetrics::query(Product::query())
->count()
->byMonth()
->trends();
 
// generate trends of orders amount's sum for the last 6 months of the current year including current month
LaravelMetrics::query(Order::query())
->sum('amount')
->byMonth(6)
->trends();
 
// generate total orders amount's sum
LaravelMetrics::query(Order::query())
->sum('amount')
->byYear()
->metrics();
 
// generate total product count for the current day
LaravelMetrics::query(Product::query())
->count()
->byDay(1)
->metrics();
  • Using custom query
LaravelMetrics::query(
Post::query()->where('user_id', auth()->id())
)
->count()
->byDay()
->trends();
  • Using custom date column
LaravelMetrics::query(Post::query())
->count()
->byDay()
->dateColumn('published_at')
->trends();
  • Using date range
LaravelMetrics::query(Post::query()))
->count()
->between('2020-05-01', '2022-08-21')
->trends();
  • Using custom label column
LaravelMetrics::query(Order::query())
->count()
->byMonth(12)
->labelColumn('status')
->trends();
  • Using custom table
LaravelMetrics::query(
Order::query()->join('users', 'orders.id', 'users.order_id')
)
->count()
->table('users')
->labelColumn('name')
->trends();

Recent Courses on Laravel Daily

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.