PHP code example of beranidigital / laravel-trend

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

    

beranidigital / laravel-trend example snippets


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

// Average user weight where name starts with a over a span of 11 years, results are grouped per year
$trend = Trend::query(User::where('name', 'like', 'a%'))
    ->between(
        start: now()->startOfYear()->subYears(10),
        end: now()->endOfYear(),
    )
    ->perYear()
    ->average('weight');

// Model
Trend::model(Order::class)
    ->between(...)
    ->perDay()
    ->count();

// More specific order query
Trend::query(
    Order::query()
        ->hasBeenPaid()
        ->hasBeenShipped()
)
    ->between(...)
    ->perDay()
    ->count();

Trend::model(Order::class)
    ->dateColumn('custom_date_column')
    ->between(...)
    ->perDay()
    ->count();

Flowframe\Trend\Trend::$carbonFormats['minute'] = 'Y-m-d H:i:00';
Flowframe\Trend\Trend::$carbonFormats['hour'] = 'Y-m-d H:00:00';
Flowframe\Trend\Trend::$carbonFormats['day'] = 'd-M-Y';
Flowframe\Trend\Trend::$carbonFormats['week'] = 'W/Y';
Flowframe\Trend\Trend::$carbonFormats['month'] = 'Y-m';
Flowframe\Trend\Trend::$carbonFormats['year'] = 'Y';