Generate metrics and trends data from your database.
You can install the package via composer:
composer require eliseekn/laravel-metrics
<?php
namespace App\Http\DashboardController;
use Eliseekn\LaravelMetrics\LaravelMetrics;
use Illuminate\Http\Request;
Class DashboardController extends Controller
{
public function index(Request $request)
{
//generate trends data for your chart component
$expensesTrends = LaravelMetrics::getTrends('expenses', 'amount', LaravelMetrics::YEAR, LaravelMetrics::SUM);
$userTrends = LaravelMetrics::getTrends('users', 'id', LaravelMetrics::QUATER_YEAR, LaravelMetrics::COUNT);
//generate metrics data
$totalExpenses = LaravelMetrics::getMetrics('expenses', 'amount', LaravelMetrics::QUATER_YEAR, LaravelMetrics::SUM);
//generate metrics data for a custum perod
$totalUsers = LaravelMetrics::getMetrics('users', 'id', ['2021-01-01', '2021-12-31'], LaravelMetrics::MAX);
return view('dashboard', compact('expensesTrends', 'userTrends', 'totalExpenses', 'totalUsers'));
}
}
LaravelMetrics::TODAY
LaravelMetrics::DAY
LaravelMetrics::WEEK
LaravelMetrics::MONTH
LaravelMetrics::YEAR
LaravelMetrics::QUATER_YEAR
LaravelMetrics::HALF_YEAR
LaravelMetrics::COUNT
LaravelMetrics::AVERAGE
LaravelMetrics::SUM
LaravelMetrics::MAX
LaravelMetrics::MIN
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
You can find a demo project here.
This package was generated using the Laravel Package Boilerplate.