PHP code example of zaimealabs / aggregate

1. Go to this page and download the library: Download zaimealabs/aggregate 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/ */

    

zaimealabs / aggregate example snippets


// Totals per month
    $model = Aggregate::model(User::class)
        ->between(
            start: now()->startOfYear(),
            end: now()->endOfYear(),
        )
        ->perMonth()
        ->count();

// Count users register per year, results are grouped per month
    $query = Aggregate::query(User::whereNotNull('email_verified_at'))
        ->between(
            start: now()->startOfYear()->subYears(10),
            end: now()->endOfYear(),
        )
        ->perYear()
        ->count();

// Average user calendar activity where record type is work with a over a span of 11 years, results are grouped per year
    $query = Aggregate::query(Record::where('type', 'work'))
        ->dateColumn('scheduled_at')
        ->between(
            start: now()->startOfYear()->subYears(10),
            end: now()->endOfYear())
        ->perYear()
        ->sumTime('duration');

->dateColumn('pointed_date_column')