PHP code example of toneflix-code / laravel-stats

1. Go to this page and download the library: Download toneflix-code/laravel-stats library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toneflix-code / laravel-stats example snippets


use ToneflixCode\Stats\Ranger;
use ToneflixCode\Stats\Stats;

$stats = (new Stats())
    ->registerMetric(
        modelClass: \App\Models\User::class,
        metric: Metric::COUNT,
        period: Ranger::years('created_at', 'M Y')->fromDate(now()->subYears(1))->toDate(now()->subYears(1)->addYear())->range('1 month'),
        aggregateField: 'id',
        label: 'old_users'
    )
    ->registerMetric(
        modelClass: \App\Models\User::class,
        period: ['from' => now()->subYears(1), 'to' => now()],
        metric: Metric::COUNT,
        aggregateField: 'id',
    )
    ->registerMetric(
        modelClass: new \App\Models\User(),
        period: ['from' => now()->subYears(1), 'to' => now()],
        metric: Metric::COUNT,
        callback: fn ($query) => $query->find(1)->posts(),
        aggregateField: 'id',
    )
    ->build()