PHP code example of zaimealabs / metrics

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


    use ZaimeaLabs\Metrics\HasMetrics;

    class User extends Authenticable
    {
        use HasMetrics;
    }

    $user->incrementMetric(config('metric.enums.Logins'), 1);

    $user->decrementMetric(config('metric.enums.Logins'), 1);

    $user->metrics()->where('name', 'logins')->value('value');

    enum UserMetric: string
    {
        case Logins = 'logins';
    }

    $user->incrementMetric(UserMetric::Logins->value, 1);

    $user->decrementMetric(UserMetric::Logins->value, 1);

    $user->metrics()->where('name', 'logins')->value('value');

    $user->incrementMetric(UserMetric::Logins->value, 1, /*withDate*/ false);

    $user->decrementMetric(UserMetric::Logins->value, 1, /*withDate*/ false);

    $user->incrementMetric(UserMetric::Logins->value, /*withDate*/ 1, true, /*month*/ 04, /*year*/ 2023, /*day*/ 01);

    $user->decrementMetric(UserMetric::Logins->value, /*withDate*/ 1, true, /*month*/ 04, /*year*/ 2023, /*day*/ 01);
bash
    php artisan vendor:publish --tag=metric
bash
    php artisan migrate