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 yearLaravelMetrics::query(Product::query()) ->count() ->byMonth() ->trends(); // generate trends of orders amount's sum for the last 6 months of the current year including current monthLaravelMetrics::query(Order::query()) ->sum('amount') ->byMonth(6) ->trends(); // generate total orders amount's sumLaravelMetrics::query(Order::query()) ->sum('amount') ->byYear() ->metrics(); // generate total product count for the current dayLaravelMetrics::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
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read
Laravel 13 Eloquent: Expert Level
41 lessons
1 h 34 min